Rstudio: Cmd + C/V not working in editor

2019-04-05 17:20发布

问题:

I have used pipe to copy and paste data between Rstudio (v0.99.467) and Excel on my Mac OSX 10.9.5.

pipe("pbcopy", "w")
pipe("pbpaste")

For some time, I tried to use pipe("pbcopy", "r"), but Rstudio is not responding (because my code is wrong). After a while, I found Cmd + C/V is not working in the editor any more (but it still works in the R console). I re-install R-studio, removed .rstudio-desktop, the problem still exists. Does anyone know what is going on? Can I remove the .bash file that stores the Rstudio shortcut preferences (assuming re-install won't delete it)? BTW, where is the shortcut .bash file in Rstudio?

回答1:

On OSX Mojave using R 3.5.1, you can use the following block to capture the clipboard:

clipboard <- system("pbpaste", intern = T)

I can also confirm that the following block is working:

clipboard <- scan(pipe("pbpaste", "r"), what = character())

However, connections are sometimes tricky to work with. For example:

clipboard <- readLines(pipe("pbpaste", "r"))

Returns an empty character vector, likely because there's no newline terminator in the clipboard!



标签: r rstudio