Reputation: 52198
Sometimes we copy/paste a string into RStudio, in which case we need to manually surround the text with quotes.
Is there a native way to paste with automatic quoting?
If the clipboard contained here is my text
, such a shortcut would result in "here is my text"
being pasted in the R console/script pane.
Upvotes: 0
Views: 446
Reputation: 173793
If you want a way to make the text contents of your Clipboard reusable in a script you can do
dput(readClipboard())
This has the benefit of automatically making multi-line text into a concatenated character vector. For example if I copy:
Alas, poor Yorick!
I knew him, Horatio;
a fellow of infinite jest,
of most excellent fancy;
Then I can do
dput(readClipboard())
# c("Alas, poor Yorick! ", "I knew him, Horatio; ", "a fellow of infinite jest, ",
# "of most excellent fancy; ")
Upvotes: 0
Reputation: 269371
This can be done in R:
x <- readClipboard()
x
## [1] "Here is my text"
This also works:
x <- readLines(stdin())
...paste clipboard into R & press ctrl-z (windows) or ctrl-d (unix)...
x
## [1] "Here is my text"
Upvotes: 2