Simple utility functions to read and write from the system clipboards of
Windows, OS X, and Unix-like systems (which require either xclip or
xsel.)
Installation
Install from CRAN
install.packages("clipr")
Or try the development version
remotes::install_github("mdlincoln/clipr")
Usage
clipr is pipe-friendly, and will default to returning the same object
that was passed in.
library("clipr")
#> Welcome to clipr. See ?write_clip for advisories on writing to the clipboard in R.
res <- write_clip(c("Text", "for", "clipboard"))
res
#> [1] "Text" "for" "clipboard"
cb <- read_clip()
cb
#> [1] "Text" "for" "clipboard"
To capture the string that clipr writes to the clipboard, specify
return_new = TRUE. Character vectors with length > 1 will be
collapsed with system-appropriate line breaks, unless otherwise
specified
write_clip also tries to intelligently handle data.frames and
matrices, rendering them with write.table so that they can be pasted
into a spreadsheet like Excel.
read_clip_tbl will try to parse clipboard contents from spreadsheets
into data frames directly.
Developing with clipr
See the “Developing with clipr” vignette included with this package for
advisories on writing code that calls clipr functions.
Nice uses of clipr
(a non-comprehensive list)
reprex by
@jennybc takes R code on the clipboard
and renders a reproducible example from it, ready to then paste on
to GitHub, Stack Overflow, or the like.
datapasta by
@milesmcbain eases the copying and
pasting of R objects in and out of different sources (Excel, Google
Sheets).
clipr
Simple utility functions to read and write from the system clipboards of Windows, OS X, and Unix-like systems (which require either xclip or xsel.)
Installation
Install from CRAN
Or try the development version
Usage
clipr is pipe-friendly, and will default to returning the same object that was passed in.
To capture the string that clipr writes to the clipboard, specify
return_new = TRUE. Character vectors with length > 1 will be collapsed with system-appropriate line breaks, unless otherwise specifiedwrite_clipalso tries to intelligently handle data.frames and matrices, rendering them withwrite.tableso that they can be pasted into a spreadsheet like Excel.read_clip_tblwill try to parse clipboard contents from spreadsheets into data frames directly.Developing with clipr
See the “Developing with clipr” vignette included with this package for advisories on writing code that calls clipr functions.
Nice uses of clipr
(a non-comprehensive list)
Matthew Lincoln