Convert copied dput output (in clipboard) to a data frame or tibble/tribble?

Just so I’m understanding what you’re looking for — you want to be able to convert dput() output (of a data frame) into an equivalent data.frame() call so that you can… replace the dput() output in an example for the purposes of further sharing? Or are you trying to automate making your own data frames into a representation that looks prettier in examples you want to share?

(I’m assuming that if you just wanted to work with someone else’s example, you’d run the line with all the ugly structure() stuff and then you’d have the data frame object in your environment).

I’m with you on RStudio’s ugly dput() output pasting. If you haven’t seen it already, we had a whole thread on that, including a couple of workarounds.

Personally I still can’t figure out the principles that the current auto-indent-on-paste algorithm is using to arrive at this ugly indentation — it’s not the same as the auto-format method (Code menu), because that makes a less-ugly but way too long version. If somebody else gets the logic that leads to the ugly, I’d love to hear an explanation!

2 Likes