Last active
December 14, 2015 18:19
-
-
Save mrdwab/5128419 to your computer and use it in GitHub Desktop.
Read pasted output at Stack Overflow into R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
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
Might I suggest to add to generalize this to MAC users with readLines(pipe("pbpaste")) equivalent to readLines("clipboard")),