You can access clipboard in R but there are different implementations for windows, mac os and linux. This is a simple generic function that works both for windows and mac os. I plan to add linux support later.
For windows it just call utils::readClipboard()
, utils::writeClipboard()
. Since these functions return and take character vector, I have to make the mac os version with same type of return value and input parameter. One side effect is that when writing lines into clipboard, there will be extra new line at the end.
To read the clipboard, just run clip_read_lines()
. To write to the clipobard, just run clip_write_lines(c("line 1", "line 2 \n and line 3"))
.