R Tools for Data Copy-Pasta

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

CRAN status. Downloads

The Goods


Introducing datapasta

datapasta is about reducing resistance associated with copying and pasting data to and from R. It is a response to the realisation that I often found myself using intermediate programs like Sublime to munge text into suitable formats. Addins and functions in datapasta support a wide variety of input and output situations, so it (probably) "just works". Hopefully tools in this package will remove such intermediate steps and associated frustrations from our data slinging workflows.


  • 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.


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


Use with RStudio

Getting data into source

At the moment this package contains these RStudio addins that paste data to the cursor:

  • tribble_paste which pastes a table as a nicely formatted call to tibble::tribble()
    • Recommend 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:
  • df_paste which pastes a table on the clipboard as a standard data.frame definition rather than a tribble call. This has certain advantages in the context of reproducible examples and educational posts. Many thanks to Jonathan Carroll for getting this rolling and coding the bulk of the feature.
    • Recommend Ctrl + Alt + Shift + d as shortcut.

Massaging data in source

There are two Addins that can help with creating and aliging data in your editor:

  • Fiddle Selection will perform magic on a selection. It can be used to:

    • Turn raw data delimited by any combination of commas, spaces, and newlines into a c() expression
    • Pivot a c() expr between horizontal and vertical layout.
    • Reflow messy tribble() and data.frame() exprs.
    • Recommend Ctrl +Shift + f as shortcut.
  • Toggle Vector Quotes will toggle a c() expr between all elements wrapped in "" and all bare unquoted form. Handy in combination with above to save mucho keystrokes.

    • Recommend Ctrl +Shift + q as shortcut.

Getting Data out of an R session

There are two R functions available that accept R objects and output formatted text for pasting to a reprex or other application:

  • dpasta accepts tibbles, data.frames, and vectors. Data is output in a format that matches in input class. Formatted text is pasted at the cursor.

  • dmdclip accepts the same inputs as dpasta but inserts the formatted text onto the clipboard, preceded by 4 spaces so that is can be as pasted as a preformatted block to Github, Stackoverflow etc.

Use with other editors

The only hard dependency of datapasta is readr for type guessing. All the above *paste functions can be called directly instead of as an addin, and will fall back to console output if the rsudioapi is not available.

On system without access to the clipboard (or without clipr installed) datapasta can still be used to output R objects from an R session. dpasta is probably the only function you care about in this scenario.

Custom Installation

datapasta imports clipr and rstudioapi so as to make installation smooth and easy for most users. If you wish to avoid installing an rstudioapi you will never use you can use:

  • install.packages("datapasta", dependencies = "Depends").
  • Followed by install.packages("clipr") to enable clipboard features.


  • tribble_paste works well with CSVs, 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.
  • Nested list columns have limited support with tribble_paste()/dpasta(). Nested lists of length 1 fail unless all are length 1 - It's complicated. You still get some output so it might be viable to fix and reflow with Fiddle Selection. Tread with caution.

Prior art

This package is made possible by mdlincon's 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 am interested in expanding the types of objects supported by the output functions dpasta. I would also like to eventualy have Fiddle Selection to pivot function calls and named vectors. Feel free to contribute your ideas to the open issues.


0 to datapasta in 64 seconds via a video vignette:

Datapasta in 64 seconds


datapasta 3.0.0 'Colander Helmet'

  • When pasting from clipboard it now attempts to guess if there is no header row, in the case where the clipboard is all data. If you're lucky it will create a default header for you when pasting (V1, V2, V3 etc.).
  • dpasta() will now handle tribbles with R classes that cannot be represented in tribble form. It falls back to their character representation. This works well for things like dates.
  • New addin: 'Fiddle Selection'. This is a kind of magic wand that can be waved over RStudio editor selections to: Reflow messy tribble and data.frame definitions, create c() expressions from raw data, and pivot c() exprs between vertical and horizontal format.
  • New addin: 'Toggle Vector Quotes'. Given a horizontal or vertical c() expr, it will toggle all elements between quoted and bare format.
  • Complies with new CRAN policy on clipboard use. You cannot write to the clipboard in non-interactive sessions with dmdclip() - Why would you?. Tests containing clipboard use are skipped on CI and CRAN.

datapasta 2.0.1

  • Added a trailing newline after all pastes, this works much nicer for console output.
  • Fixed handling of backslashes. Relying on built-in function deparse() for escaping chars that need it.

datapasta 2.0.0 'Fusilli Jerry'

  • Added the ability to parse objects from R and output as neatly formatted tibbles, dataframes and vectors with dpasta. The clipboard is not involved.
  • Added the ability to send these same types of objects to the clipboard formatted for markdown output with dmdclip.
  • Package can now operate in a close to fully featured way in editors other than RStudio. Output goes to console rather than cursor.
  • Added hooks for output customisation with _construct() functions that return the formatted output as an R character vector.
  • The decimal mark can be set for numeric data with dp_set_decimal_mark.
  • User can now paste natural looking comma separated lists as vectors, with automatic comma-splitting and whitespace trimming.

datapasta 1.1.0 'CopyPesto'

  • Added df_paste() which pastes a table from the clipboard using a nicely formatted call to data.frame() rather than tribble()
  • Better handling for empty lines that get accidently copied onto clipboard with table. Gracefully ignored.

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.


3.0.0 by Miles McBain, 2 months ago


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], Mark Dulhunty [ctb]

Documentation:   PDF Manual  

MIT + file LICENSE license

Imports readr, clipr, rstudioapi

Suggests tibble, testthat, knitr, rmarkdown, covr

See at CRAN