Last active
December 16, 2015 13:39
-
-
Save mrdwab/5443094 to your computer and use it in GitHub Desktop.
Rough concept of `readSOfwf`
This file contains 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
readClip <- function(){ | |
OS <- Sys.info()["sysname"] | |
cliptext <- switch(OS, | |
Darwin = { | |
con <- pipe("pbpaste") | |
text <- readLines(con) | |
close(con) | |
text | |
}, | |
Windows = readClipboard(), | |
readLines("clipboard")) | |
cliptext | |
} |
This file contains 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
readSOfwf <- function(dropFirst = FALSE, | |
stringsAsFactors = FALSE, | |
header = TRUE, | |
out = "mydf") { | |
myStrings <- gsub("^\\s+", "", | |
gsub("^#|^##", "", | |
gsub("^\\s+", "", | |
suppressWarnings(readClip())))) | |
myStrings <- gsub("\\s\\s+", ",", myStrings) | |
temp <- read.csv(text = myStrings, header = header, | |
stringsAsFactors = stringsAsFactors) | |
if (isTRUE(dropFirst)) temp <- temp[-1] | |
else temp <- temp | |
assign(out, temp, envir = .GlobalEnv) | |
message("data.frame ", dQuote(out), " created in your workspace") | |
temp | |
} |
This file contains 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
# Test Cases | |
Copy the following examples to clipboard and read in with `readSOfwf()`. To drop the rows that might result, set `dropFirst = TRUE`. | |
http://stackoverflow.com/questions/16153920/transforming-a-min-and-a-max-value-into-a-range-of-values | |
NYC1 1/1/2013 2/1/2013 Open | |
NYC1 2/2/2013 2/3/2013 Closed for Inspection | |
Boston1 1/1/2013 2/5/2013 Open | |
http://stackoverflow.com/a/16142354/1270695 | |
# heat.J. | |
# 1995-07-01 02:00:00 1000 | |
# 1995-07-01 03:00:00 1150 | |
## Other potential cases | |
The following are more appropriately read using `readSO()`. | |
http://stackoverflow.com/questions/16162342/insert-data-frame-from-r-to-mongodb | |
V2 V1 V3 V4 polarity emotion | |
1 342521635332_318304224958367 FB 2013-03-15 6:43 PM positive <NA> | |
2 342521635332_325506614238815 FB 2013-03-08 8:23 PM neutral sad | |
3 342521635332_347654842010216 FB 2013-02-22 8:13 PM positive <NA> | |
4 342521635332_567940913224072 FB 2013-02-22 6:27 PM neutral <NA> | |
5 342521635332_318826431554118 FB 2013-02-22 2:22 PM positive joy | |
6 342521635332_215298638612191 FB 2013-02-20 8:09 PM negative angry | |
7 342521635332_407970722630311 FB 2013-02-15 8:48 PM neutral joy | |
http://stackoverflow.com/a/16143887/1270695 | |
## c1 c2 | |
## 1 a 1 | |
## 2 b 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment