RStudio addins and R functions that make copy-pasting vectors and tables to text painless.
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.
xclip. These applications provide an interface to X selections (clipboard-like).
sudo apt-get install xsel- it's 72kb...
At the moment this package contains these RStudio addins that paste data to the cursor:
tribble_pastewhich pastes a table as a nicely formatted call to
vector_pastewhich will paste delimited data as a vector definition, e.g.
vector_paste_verticalwhich will paste delimited data as a vertically formatted vector definition.
c("Mint", "Fedora", "Debian", "Ubuntu", "OpenSUSE")
df_pastewhich pastes a table on the clipboard as a standard
data.framedefinition rather than a
tribblecall. 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.
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:
c()expr between horizontal and vertical layout.
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.
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.
The only hard dependency of
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
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.
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").
install.packages("clipr")to enable clipboard features.
tribble_pasteworks 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. :(
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.
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.
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.
datapasta in 64 seconds via a video vignette:
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.
c()expressions from raw data, and pivot
c()exprs between vertical and horizontal format.
c()expr, it will toggle all elements between quoted and bare format.
dmdclip()- Why would you?. Tests containing clipboard use are skipped on CI and CRAN.
dpasta. The clipboard is not involved.
_construct()functions that return the formatted output as an R character vector.
df_paste()which pastes a table from the clipboard using a nicely formatted call to
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.
NEWS.mdfile to track changes to the package.