Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mdlincoln/clipr
R functions for reading and writing from the system clipboard
https://github.com/mdlincoln/clipr
clipboard rstats
Last synced: 3 months ago
JSON representation
R functions for reading and writing from the system clipboard
- Host: GitHub
- URL: https://github.com/mdlincoln/clipr
- Owner: mdlincoln
- Created: 2015-08-27T16:50:19.000Z (about 9 years ago)
- Default Branch: main
- Last Pushed: 2023-08-21T20:32:17.000Z (about 1 year ago)
- Last Synced: 2024-07-18T22:39:34.148Z (4 months ago)
- Topics: clipboard, rstats
- Language: R
- Homepage: http://matthewlincoln.net/clipr/
- Size: 576 KB
- Stars: 152
- Watchers: 5
- Forks: 24
- Open Issues: 6
-
Metadata Files:
- Readme: README.Rmd
Awesome Lists containing this project
- jimsghstars - mdlincoln/clipr - R functions for reading and writing from the system clipboard (R)
README
---
output: github_document
---```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```clipr
=====[![CRAN status.](https://www.r-pkg.org/badges/version/clipr)](https://www.r-pkg.org/pkg/clipr)
![Downloads, grand total](https://cranlogs.r-pkg.org/badges/grand-total/clipr)
[![R-CMD-check](https://github.com/mdlincoln/clipr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/mdlincoln/clipr/actions/workflows/R-CMD-check.yaml)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
```{r, eval = FALSE}
install.packages("clipr")
```Or try the development version
```{r, eval = FALSE}
remotes::install_github("mdlincoln/clipr")
```## Usage
clipr is pipe-friendly, and will default to returning the same object that was passed in.
```{r pipe-friendly}
library("clipr")res <- write_clip(c("Text", "for", "clipboard"))
rescb <- 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
```{r return-new}
cb <- write_clip(c("Text", "for", "clipboard"), return_new = TRUE)
cbcb <- 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.
```{r tbl}
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.
## 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)
1. [reprex](https://github.com/tidyverse/reprex) by [\@jennybc](https://github.com/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.
2. [datapasta](https://github.com/milesmcbain/datapasta) by [\@milesmcbain](https://github.com/milesmcbain) eases the copying and pasting of R objects in and out of different sources (Excel, Google Sheets).---
[Matthew Lincoln](https://matthewlincoln.net)