• Stars
    star
    874
  • Rank 52,219 (Top 2 %)
  • Language
    R
  • License
    Other
  • Created about 8 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

On top of spaghetti, all covered in cheese....

datapasta 3.1.1 'Leave to Simmer'

r-universe status badge CRAN status. Downloads

The Goods

pow!

Introducing datapasta

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.

Prerequisites

  • Linux users will need to install either xsel or xclip. These applications provide an interface to X selections (clipboard-like).
    • For example: sudo apt-get install xsel - it's 72kb...
  • Windows and MacOS have nothing extra to do.

Installation

R Universe (preferred)

  1. install with R universe repo:
install.packages(
   "datapasta", 
   repos = c(mm = "https://milesmcbain.r-universe.dev", getOption("repos")))
  1. Set the keyboard shortcuts using Tools -> Addins -> Browse Addins, then click Keyboard Shortcuts...

CRAN (outdated)

For now, no further versions of datapasta will be going to CRAN. There are some known bugs in the CRAN version that have been fixed in 3.1.1.

  1. install.packages("datapasta")

Usage

Use with RStudio

Getting data into source

At the moment this package contains these RStudio addins that paste data to the cursor:

  • tribble_paste which pastes a table as a nicely formatted call to tibble::tribble()
    • Recommend Ctrl + Shift + t as shortcut.
    • Table can be delimited with tab, comma, pipe or semicolon.
  • vector_paste which will paste delimited data as a vector definition, e.g. c("a", "b") etc.
    • Recommend Ctrl + Alt + Shift + v as shortcut.
  • vector_paste_vertical which will paste delimited data as a vertically formatted vector definition.
    • Recommend Ctrl + Shift + v as shortcut
    • example output:
c("Mint",
  "Fedora",
  "Debian",
  "Ubuntu",
  "OpenSUSE")
  • df_paste which pastes a table on the clipboard as a standard data.frame definition rather than a tribble call. 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.
    • Recommend Ctrl + Alt + Shift + d as shortcut.
  • dt_paste which is the same as df_paste, but for data.table.

Massaging data in source

There are two Addins that can help with creating and aligning data in your editor:

  • Fiddle Selection will perform magic on a selection. It can be used to:

    • Turn raw data delimited by any combination of commas, spaces, and newlines into a c() expression
    • Pivot a c() expr between horizontal and vertical layout.
    • Reflow messy tribble() and data.frame() exprs.
    • Recommend Ctrl +Shift + f as shortcut.
  • 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.

    • Recommend Ctrl +Shift + q as shortcut.

Getting Data out of an R session

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.

Use with other editors

The only hard dependency of datapasta is 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 rstudioapi is not available.

On system without access to the clipboard (or without clipr installed) 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.

Custom Installation

datapasta imports clipr and 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").
  • Followed by install.packages("clipr") to enable clipboard features.

Pitfalls

  • tribble_paste works 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. :(
  • Quoted csv data, where the quotes contain commas will not be parsed correctly.
  • Nested list columns have limited support with tribble_paste()/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.

Prior art

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.

Future developments

I am interested in expanding the types of objects supported by the output functions dpasta. I would also like to eventually have Fiddle Selection to pivot function calls and named vectors. Feel free to contribute your ideas to the open issues.

Bonus

0 to datapasta in 64 seconds via a video vignette:

Datapasta in 64 seconds

More Repositories

1

breakerofchains

Break your chain at the cursor line. Run the first bit. See the output. Be free.
R
152
star
2

capsule

An inversion of renv for low effort reproducible R package libraries
R
143
star
3

gistfo

Turn your RStudio untitled tabs into gists. You monsters.
R
140
star
4

paint

paint the data
R
137
star
5

friendlyeval

A friendly interface to tidyeval/rlang that will excuse itself when you're done.
R
107
star
6

fnmate

A function definition generator.
R
93
star
7

tflow

An opinionated lightweight template for smooth targets flows.
R
87
star
8

dflow

Automatically setup a drake project
R
80
star
9

markdrive

Edit Google docs in Markdown with a little help from #rstats
R
71
star
10

slippymath

R functions for dealing with slippy map tile servers.
R
65
star
11

esscss

This repository collects links to ESS configurations shared by #rstats community members.
57
star
12

packup

Collect, stow, and alphabetise library() calls in your R files.
R
57
star
13

deplearning

Detect, install and update R source dependencies.
R
52
star
14

rmdgh

Put Github in your Rmd and Rmd in your GitHub
R
52
star
15

vsconfig

My config for R in VSCode
R
47
star
16

inlegend

Styling for inset ggplot2 map legends
R
41
star
17

nycr_meetup_talk

That Feeling of Workflowing
39
star
18

wisegroup

Now I am become death, destroyer of groups....
R
39
star
19

portal

move data between R processes
R
35
star
20

git_4_sci

A 3.5 hour introduction to basic shell and git/GitHub workflow for ACMES researchers.
CSS
28
star
21

really_useful_engines

R
24
star
22

rmdocs

browse help files as Rmarkdown documents
R
19
star
23

mufflr

Experimental RStudio addins for pipe and assign.
R
19
star
24

flippingtables

turn the tables on data.frame printing
R
16
star
25

mvtview

a Mapbox vector tile server and viewer for R
R
16
star
26

mmmisc

My Library of R Helpers
R
14
star
27

rstudioconf_talk

my rstudio conf talk
R
12
star
28

RmdComment

A simple comment CSS for linking in R markdown
R
11
star
29

milesmcbain.com

Seeing if I can make my website look any good with distill...
HTML
10
star
30

hexbin_qld

An example of hexbinning for mapping using {h3jsr}, {dplyr}, {sf}, and {mapdeck}
R
10
star
31

chradle

A bare bones #rstats test harness for Chrome/Chromium
R
7
star
32

tidycourse

An introduction to the tidyverse for R users. First delivery RezBaz 2017, Brisbane.
R
7
star
33

covid19

some analysis of covid19
R
6
star
34

shist

Shifting histograms - they're the shist
R
6
star
35

ghost_https_R_blog

A docker-compose.yml for an R blogger using Ghost
6
star
36

tidy_aus_ssm

Scrubadubdub
R
6
star
37

burgr_package_discovery

A short talk on ways I discover R packages, and R package stats.
CSS
5
star
38

noprobs

Tidy error data
R
5
star
39

remodel

Turn that LaTeX frown upsidedown.
R
5
star
40

shiny_SMILE

A Shiny web interface to SMILE Bayesian Networks
R
4
star
41

vr_vs_sp

Spatial meets VR with a little help from R
HTML
4
star
42

null_island

A stab at communicating science with VR for Bayes on the beach 2017
JavaScript
4
star
43

sicp_notes

SICP notes and exercises
HTML
3
star
44

lackadaisical

experments with unit testing for lazy people
3
star
45

git_workshop

An introduction to git for me
3
star
46

AMSI_2017_MSBD_Talk

My personal opinions on things that are useful to know about when moving into the discipline of big data.
HTML
3
star
47

mmstyle

My rstats code formatter
R
2
star
48

drake_make

makefile as drake plan
R
2
star
49

haircut

Give your strings a haircut with tidyverse-friendly regex.
R
2
star
50

mbtiles_example

code from my vector tiles blog post
R
2
star
51

mesh_all_the_things

Mesh all the things
R
2
star
52

burgr_20170913_github

Some notes for my presentation about git/github
CSS
1
star
53

unmacify_vscode

making my vscode on Mac work the same as Windows and Linux
R
1
star
54

recover_demo

stop() take a breath and recover()
R
1
star
55

MXB344

Course Materials and Assignments for MXB344
HTML
1
star
56

old_blog_source

Blogdown Source for GitHub pages site.
HTML
1
star
57

aus_ssm_census

Overlaying 2016 Census Data on the 2017 Same Sex Marriage Postal Vote
R
1
star
58

r2vr2_meshes_in_webvr

R
1
star
59

journalr

A repository for my proposal for an R code/data journalling tool.
HTML
1
star
60

servethis

Serve the current folder on a webserver using whatever Python is available
Shell
1
star
61

nycr_meetup_talk_code

Coded live in my talk at the New York Open Statistical Programming Meetup
R
1
star
62

packrat_demo

An example repo using a lightweight workflow for dependency management with packrat
HTML
1
star
63

r2vr3_shading

Part three of the #r2vr series. Shading a mesh.
R
1
star
64

keras_facial_keypoints

A quick and dirty test of R's Keras with the Kaggle Facial keypoints data.
R
1
star
65

r2vr1_uluru_mesh

Repository for code and data described in: `R2VR: Meshing Uluru From Polygons and Rasters`
R
1
star
66

juicr

R
1
star
67

classic_r_project

The classic flavour you know and maybe love
R
1
star
68

atcursor

Get the thing at the cursor using rstudioapi
R
1
star
69

ssa_targets_workshop

A half-day introduction to {targets}
1
star