Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8335911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:49:06+00:00 2026-06-09T03:49:06+00:00

I have wrapped the strwrap function into strWrap that accepts text from the clipboard

  • 0

I have wrapped the strwrap function into strWrap that accepts text from the clipboard as well as automatically writing to the clipboard. In this I am assuming the system name for the mac is Darwin. This function works on a windows machine (sorry Linux has too much variation to make it feasible & most people that would use the package this function is for would not be linux users anyway).

I modeled my function after the psych packages’s read.clipboard function. Unfortunately, I asked some people to try it out at talkstats.com who had a mac and it doesn’t work. How can I make this work for mac as well? According to this SO post my code seems like it should work for mac users as well.

If this works as expected it should be able to both read from the clipboard for mac users and write to the clipboard when finished. I have marked the mac specific lines with a # at the end for easier understanding of the problem

strWrap <-
function(text = "clipboard", width = 70) {
    if (text == "clipboard") {
        if (Sys.info()["sysname"] == "Darwin") {        #
            text <- paste(pipe("pbpaste"), collapse=" ")#
        }                                               #
        if (Sys.info()["sysname"] == "Windows") {
            text <- paste(readClipboard(), collapse=" ")
        }
    } 
    x <- gsub("\\s+", " ", gsub("\n|\t", " ", text))
    x <- strwrap(x, width = width)
    if (Sys.info()["sysname"] == "Windows") {
        writeClipboard(x, format = 1)
    }
    if (Sys.info()["sysname"] == "Darwin") {           #
        j <- pipe("pbcopy", "w")                       #
        cat(x, file = j)                               #
        close(j)                                       # 
    }                                                  #
    writeLines(x)
}

X <- "Two households, both alike in dignity, In fair Verona, where we lay
our scene, From ancient grudge break to new mutiny, Where civil blood
makes civil hands unclean. From forth the fatal loins of these two
foes A pair of star-cross'd lovers take their life; Whose
misadventured piteous overthrows Do with their death bury their
parents' strife. The fearful passage of their death-mark'd love, And
the continuance of their parents' rage, Which, but their children's
end, nought could remove, Is now the two hours' traffic of our stage;
The which if you with patient ears attend"

strWrap(X, 70)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T03:49:07+00:00Added an answer on June 9, 2026 at 3:49 am

    pipe returns a connection object. You need to read from the connection.
    For example

    pcon <- pipe("pbpaste")
    text <- paste(scan(pcon, what="character", quiet=TRUE), collapse=" ")
    close(pcon)
    

    This works on my mac.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some images that are wrapped within containers like this: <div id=swatchcontainer> <div
I insert data from a util.List into a JTable with beansbinding.I have wrapped an
I have wrapped calls to firebugs console.log in a logging function (that checks for
I have 3 gits wrapped by a manifest file (this manifest file is in
I have a large body of text which has several sentences wrapped in yada
I have an overloaded function which I want to pass along wrapped in a
Have textarea wrapped in parent div element. This textarea becomes visible only when parent
Everyone, I have a WPF app that has a canvas that I have wrapped
I have a function in C++ that returns a vector<vector<double> > object. I have
I have a C++ library that I call from Java via JNI. There's a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.