Skip to content

Instantly share code, notes, and snippets.

@mrdwab
Last active December 14, 2015 18:19
Show Gist options
  • Save mrdwab/5128419 to your computer and use it in GitHub Desktop.
Save mrdwab/5128419 to your computer and use it in GitHub Desktop.
Read pasted output at Stack Overflow into R
read.so <- function(sep = "", header = TRUE, out = "mydf") {
OS <- ifelse(Sys.info()["sysname"] == "Darwin", "Mac", "others")
temp <- switch(
OS,
Mac = {
suppressWarnings(
read.table(text = gsub("^#", "", pipe("pbpaste")), header = header,
stringsAsFactors = FALSE, sep = sep))
},
others = {
suppressWarnings(
read.table(text = gsub("^#", "", readLines("clipboard")),
header = header, stringsAsFactors = FALSE, sep = sep))
})
assign(out, temp, envir = .GlobalEnv)
message("data.frame ", dQuote(out), " created in your workspace")
temp
}
@agstudy
Copy link

agstudy commented Mar 10, 2013

Might I suggest to add to generalize this to MAC users with readLines(pipe("pbpaste")) equivalent to readLines("clipboard")),

@mrdwab
Copy link
Author

mrdwab commented Mar 10, 2013

if (Sys.info()["sysname"] == "Darwin") { 
read.table(pipe("pbpaste"), sep = sep, ...) 
} 
else { 
read.table("clipboard", sep = sep, ...) 
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment