Using datapasta with reprex
While using a built-in dataset for a reprex is ideal, sometimes you need to troubleshoot code with a bit of outside data. Meet datapasta, a package by Miles McBain for “reducing resistance associated with copying and pasting data to and from R.” Like reprex, datapasta has addin functionality, so you can select commands from the RStudio Addins and/or associate keyboard shortcuts with them for easy use.
It’s easy to copy and paste nicely formatted data from a spreadsheet
tribble_paste() functionality. I’ve found
the simplest method to be:
- Copy data from a source onto your clipboard.
- Click Paste as tribble from the datapasta section
of the RStudio Addins drop-down.
- Be sure to assign your data frame to a name, so you can use it elsewhere in your reprex.
While the output of
tribble_paste() doesn’t have the
same level of detail it would with
it works well enough for most scenarios, with the added benefit of being
easy to read on the screen.
Now let’s say you have a data frame in R that you want to use in a
reprex. You can use datapasta’s
dpasta() function to render
your object into the same format as the result of
There’s more to datapasta than discussed here, so be sure to check out its documentation. Don’t forget, when it comes to reprex, less is always more, so wield the power of datapasta wisely.