GithubHelp home page GithubHelp logo

clipr's Introduction

clipr

CRAN status. Downloads, grand total Travis-CI Build Status AppVeyor Build Status

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

devtools::install_github("mdlincoln/clipr")

Usage

library("clipr")

cb <- read_clip()

# Character vectors with length > 1 will be collapsed with system-appropriate
# line breaks, unless otherwise specified

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

cb <- write_clip(c("Text", "for", "clipboard"), breaks = ", ")
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.

tbl <- data.frame(a = c(1, 2, 3), b = c(4, 5, 6))
cb <- write_clip(tbl)
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

clipr's functionality on X11-based systems depends on the installation of additional software. Therefore, if you want to use clipr in your package, you will want to take some care in how you call it, and make sure that your package will respond gracefully if clipboard functionality is not working as expected. You can use the function clipr_available() to check if the clipboard is readable and writable by the current R session.

A few best practices will also help you responsibly test your clipr-using package on headless systems like CRAN or other testing infrastructure like Travis:

  1. Examples that will try to use read_clip() or write_clip() ought to be wrapped in \dontrun{}
  2. Tests calling clipr should be conditionally skipped, based on the output of clipr_available(). This is necessary to pass CRAN checks.
  3. If you are using Travis.ci to check your package build on Linux, consult the .travis.yml for this package, which includes code for setting the DISPLAY environment variable, installing xclip and xsel, and running a pre-build script that will set up xclip/xsel to run headlessly.
  4. If you wish to display system requirements and configuration messages to X11 users, dr_clipr() provides these.

Nice uses of clipr

(a non-comprehensive list)

  1. 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.
  2. datapasta by @milesmcbain eases the copying and pasting of R objects in and out of different sources (Excel, Google Sheets).
  3. curlconverter by @hrbrmstr translates cURL command lines into httr calls.

Matthew Lincoln

clipr's People

Contributors

mdlincoln avatar milesmcbain avatar cderv avatar lmmx avatar krivit avatar

Stargazers

atanas avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.