Importing data from Mac OS X clipboard into R studio

At first I thought importing data from the clipboard was only working in Windows using the well known

readClipboard()

or

df <- read.table(file='clipboard', sep='\t')

But couldn’t find a way that would work, so I used to do it the dummy way (i.e. save each .xls as .csv)

Turns out it could be done using pipe files, knowing that “pbpaste” corresponds to Mac’s clipboard pipe file:

df <- read.table(pipe('pbpaste'), sep='\t', header=T)

And that’s it!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s