R Tools for Data Copy-Pasta

RStudio addins and R functions that make copy-pasting vectors and tables to text painless.


Introducing datapasta

datapasta is about reducing resistance associated with copying and pasting data into R Studio. It is a response to the realisation that I often found myself using Sublime as an intermediate text munging step when copying data. Hopefully addins in this package will remove such intermediate steps from our copy-pasta workflows.

At the moment this package contains functional versions of these R Studio addins:

  • tribble_paste() which pastes a table on the clipboard as a nicely formatted call to tibble::tribble()
    • Recomend ctrl + shift + t as shortcut.
    • Table can be delimited with tab, comma, pipe or semicolon.
  • vector_paste() which will paste delimited data as a vector definition, e.g. c("a", "b") etc.
    • Recommend ctrl + alt + shift + v as shortcut.
  • vector_paste_vertical() which will paste delimited data as a vertically formatted vector definition.
    • Recommend ctrl + shift + v as shortcut
    • example output:
c("Mint",
  "Fedora",
  "Debian",
  "Ubuntu",
  "OpenSUSE")

Pitfalls

  • tribble_paste works well with csv's, excel files, and html tables, but is currently brittle with respect to irregular table structures like merged cells or multi-line column headings. For some reason Wikipedia seems chock full of these. :(
  • Quoted csv data, where the quotes contain commas will not be parsed correctly.
  • The addin does not currently work in RStudio server. The instance not have access to the local clipboard.

Prerequisites

  • Linux users will need to install either xsel or xclip. These applications provide an interface to X selections (clipboard-like).
    • For example: sudo apt-get install xsel - it's 72kb...
  • Windows and MacOS have nothing extra to do.

Installation

  1. Get the package: devtools::install_github("milesmcbain/datapasta")
  2. Set the keyboard shortcuts using Tools -> Addins -> Browse Addins, then click Keyboard Shortcuts...

Prior art

This package is made possible by [mdlincon's clipr](https://github.com/mdlincoln/clipr, and Hadley's packages tibble and readr (for data-type guessing). I especially appreciate clipr's thoughtful approach to the clipboard on Linux, which pretty much every other R clipboard package just nope'd out on.

#Future developments I'm looking at ways to address the pitfalls. The next thing I will look at is some kind of support on RStudio server, since I use this often myself. Feel free to contribute your ideas for solving these problems to the open issues.

News

datapasta 1.0.0

  • Added new addin 'Paste as vector (vertical)' to provide nicer formatting for long lists.
  • All addins now guess data types and format correctly in the source editor.
  • Empty rows in tables and empty cells in lists are formatted as NA's when pasting instead of being ignored.
  • Added vignette, automated tests etc in prep for CRAN submission.

datapasta 0.2

  • Added graceful error handling on failed parse of text on clipboard to table.
  • tribble_paste() and vector_paste() now pastse NA's as unquoted, so R will parse as propper NA.
  • tribble_paste() can parse an paste table text copied from raw delimited file e.g. csv, tsv, pipe delimited, seimi-colon delimited.
  • vector_paste() uses a space between elements.

datapasta 0.1.1

  • Added a NEWS.md file to track changes to the package.
  • Fixed the handling of NAs in tab delimited files which resulted in phantom NA columns sometimes appearing with tribble_paste()

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("datapasta")

2.0.0 by Miles McBain, 3 days ago


https://github.com/milesmcbain/datapasta


Report a bug at https://github.com/milesmcbain/datapasta/issues


Browse source code at https://github.com/cran/datapasta


Authors: Miles McBain [aut, cre], Jonathan Carroll [aut]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports readr, clipr, rstudioapi

Suggests tibble, testthat, knitr, rmarkdown


See at CRAN