Movatterモバイル変換


[0]ホーム

URL:


clipr

CRAN status.Downloads, grand totalR-CMD-checkCoverage Status

Simple utility functions to read and write from the system clipboardsof Windows, OS X, and Unix-like systems (which require either xclip orxsel.)

Installation

Install from CRAN

install.packages("clipr")

Or try the development version

remotes::install_github("mdlincoln/clipr")

Usage

library("clipr")#> Welcome to clipr. See ?write_clip for advisories on writing to the clipboard in R.cb<-read_clip()

clipr is pipe-friendly, and will default to returning the same objectthat was passed in.

res<-write_clip(c("Text","for","clipboard"))res#> [1] "Text"      "for"       "clipboard"

To capture the string that clipr writes to the clipboard, specifyreturn_new = TRUE. Character vectors with length > 1will be collapsed with system-appropriate line breaks, unless otherwisespecified

cb<-write_clip(c("Text","for","clipboard"),return_new =TRUE)cb#> [1] "Text\nfor\nclipboard"cb<-write_clip(c("Text","for","clipboard"),breaks =", ",return_new =TRUE)cb#> [1] "Text, for, clipboard"

write_clip also tries to intelligently handledata.frames and matrices, rendering them withwrite.tableso 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#> [1] "a\tb\n1\t4\n2\t5\n3\t6"

read_clip_tbl will try to parse clipboard contents fromspreadsheets into data frames directly.

Developing with clipr

See the “Developing with clipr” vignette included with this packagefor advisories on writing code that calls clipr functions.

Nice uses of clipr

(a non-comprehensive list)

  1. reprex by@jennybc takes R code on the clipboardand renders a reproducible example from it, ready to then paste on toGitHub, Stack Overflow, or the like.
  2. datapasta by@milesmcbain eases the copying andpasting of R objects in and out of different sources (Excel, GoogleSheets).

Matthew Lincoln


[8]ページ先頭

©2009-2025 Movatter.jp