How to import data from clibboard to a data-frame in R

Asked

Viewed 147 times

4

One of the advantages of using spreadsheet is that we can import data from the Clipboard.

Is there any way to do it in R?

1 answer

3


Yes, it is possible. But there are differences in Windows and Mac:

On Windows:

You can use the function readClipboard().

x <- readClipboard()

This will paste the Clipboard data as text in x. If the Clipboard data is tabular (a table, for example), you can use the function read.table()

x <- read.table(file = "clipboard", sep = "\t")

On the Mac:

On Mac, you will use the function pipe along with read.table.

x <- read.table(pipe("pbpaste"), sep="\t")
  • 1

    How it’s done on Linux?

  • @Guilhermed, I’m not running a Linux test right now, but I don’t think it’s much different. Anyway, feel free to put a complementary answer with the solution for Linux if you test and find out the correct answer.

  • 3

    I just tested it. A simple x <- read.table("clipboard") solves the problem, hug.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.