knitr::opts_chunk$set(echo = TRUE)
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.
tribble_paste()
It's easy to copy and paste nicely formatted data from a spreadsheet with datapasta's tribble_paste()
functionality. I've found the simplest method to be:
While the output of tribble_paste()
doesn't have the same level of detail it would with dput()
, it works well enough for most scenarios, with the added benefit of being easy to read on the screen.
dpasta()
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 tribble_paste()
, above.
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.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.