reprex-ing with {datapasta} 🍝

Scenario 1: from spreadsheet to reprex

So, you’ve been asked to make a reprex and you want to include a bit of data that you have in a spreadsheet.1 Meet {datapasta}, a package by Miles McBain that can make your life a whole lot easier. Once you’ve installed datapasta, you simply copy a selected number of rows from your spreadsheet (remember, this is a minimal reproducible example), and click the Paste as tribble option from the DATAPASTA section of the Addins dropdown.2

datapasta spreadsheet to reprex

datapasta spreadsheet to reprex

Once you’ve done that, be sure to include the code in your reprex, assign a name to your data frame, and you’re good to go!

Scenario 2: from R object to pasta

Now let’s say you have a data frame in R, and want to use it for a reprex. Don’t worry, datapasta’s got you covered. You can use datapasta::dpasta() to render your object into the same format as the result of Paste as tribble, above.

existing object to reprex with dpasta

existing object to reprex with dpasta

Tada! 🎉

  1. Ideally, you would use a built-in dataset, or something so minimal you could generate it in a line or two of code (see also reprex-cellence), but that’s not what’s going on in this scenario. 😉

  2. There are other options for how to paste in your rectangular data, but I like the layout of tibble::tribble() for legibility.