Reputation: 2147
I want to copy a character string output from R to the clipboard. For this, I can use the writeClipboard function as shown below:
writeClipboard("my_text")
For example, I can now paste this output to a TXT file using Strg
+ v
. The output may look as shown in the following screenshot:
As indicated by the red arrow, the output contains a newline at the end even though I have not specified this newline in my character string.
How can I create an output that does not contain this last newline at the end of my character string?
The final output should look like this:
Upvotes: 2
Views: 240
Reputation: 4067
From the documentation for writeClipboard
:
... will write a character vector as text or Unicode text with standard CR-LF line terminators.
Instead, you can use writeLines
and setup a connection to "clipboard"
like this
mytext = "Abcdefg"
writeLines(text = mytext, con = "clipboard", sep = "")
The connection to "clipboard"
can also be utilized by other functions, such as write.table
or cat
, e.g. cat(mytext, file = "clipboard")
.
Here is the documentation on the possible connections
you can use.
Upvotes: 3