knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )
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.)
Install from CRAN
install.packages("clipr")
Or try the development version
remotes::install_github("mdlincoln/clipr")
clipr is pipe-friendly, and will default to returning the same object that was passed in.
library("clipr") res <- write_clip(c("Text", "for", "clipboard")) res cb <- read_clip() cb
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
cb <- write_clip(c("Text", "for", "clipboard"), return_new = TRUE) cb cb <- write_clip(c("Text", "for", "clipboard"), breaks = ", ", return_new = TRUE) cb
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.
tbl <- data.frame(a = c(1, 2, 3), b = c(4, 5, 6)) cb <- write_clip(tbl, return_new = TRUE) cb
read_clip_tbl
will try to parse clipboard contents from spreadsheets into data frames directly.
See the "Developing with clipr" vignette included with this package for advisories on writing code that calls clipr functions.
(a non-comprehensive list)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.