File: README.md

package info (click to toggle)
r-cran-clipr 0.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 208 kB
  • sloc: sh: 13; makefile: 2
file content (103 lines) | stat: -rw-r--r-- 2,897 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103

<!-- README.md is generated from README.Rmd. Please edit that file -->

# clipr

[![CRAN
status.](http://www.r-pkg.org/badges/version/clipr)](http://www.r-pkg.org/pkg/clipr)
![Downloads, grand
total](http://cranlogs.r-pkg.org/badges/grand-total/clipr) [![Travis-CI
Build
Status](https://travis-ci.org/mdlincoln/clipr.svg?branch=master)](https://travis-ci.org/mdlincoln/clipr)
[![AppVeyor Build
Status](https://ci.appveyor.com/api/projects/status/github/mdlincoln/clipr?branch=master&svg=true)](https://ci.appveyor.com/project/mdlincoln/clipr)
[![Coverage
Status](https://img.shields.io/codecov/c/github/mdlincoln/clipr/master.svg)](https://codecov.io/github/mdlincoln/clipr?branch=master)

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
install.packages("clipr")
```

Or try the development version

``` r
devtools::install_github("mdlincoln/clipr")
```

## Usage

``` r
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 object
that was passed in.

``` r
res <- write_clip(c("Text", "for", "clipboard"))
res
#> [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

``` r

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 handle data.frames and
matrices, rendering them with `write.table` so that they can be pasted
into a spreadsheet like Excel.

``` r
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 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/jennybc/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](http://matthewlincoln.net)