Last active
August 28, 2017 12:20
-
-
Save tdhock/67f8507fee522343cc813a2affcb9d37 to your computer and use it in GitHub Desktop.
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
### Write down what package versions work with your R code, and | |
### attempt to download and load those packages. The first argument is | |
### the version of R that you used, e.g. "3.0.2" and then the rest of | |
### the arguments are package versions. For | |
### CRAN/Bioconductor/R-Forge/etc packages, write | |
### e.g. RColorBrewer="1.0.5" and if RColorBrewer is not installed | |
### then we use install.packages to get the most recent version, and | |
### warn if the installed version is not the indicated version. For | |
### GitHub packages, write "user/repo@commit" | |
### e.g. "tdhock/animint@f877163cd181f390de3ef9a38bb8bdd0396d08a4" and | |
### we use install_github to get it, if necessary. | |
works_with_R <- function(Rvers,...){ | |
pkg_ok_have <- function(pkg,ok,have){ | |
stopifnot(is.character(ok)) | |
if(!as.character(have) %in% ok){ | |
warning("works with ",pkg," version ", | |
paste(ok,collapse=" or "), | |
", have ",have) | |
} | |
} | |
pkg_ok_have("R",Rvers,getRversion()) | |
pkg.vers <- list(...) | |
for(pkg.i in seq_along(pkg.vers)){ | |
vers <- pkg.vers[[pkg.i]] | |
pkg <- if(is.null(names(pkg.vers))){ | |
"" | |
}else{ | |
names(pkg.vers)[[pkg.i]] | |
} | |
if(pkg == ""){# Then it is from GitHub. | |
## suppressWarnings is quieter than quiet. | |
if(!suppressWarnings(require(requireGitHub))){ | |
## If requireGitHub is not available, then install it using | |
## devtools. | |
if(!suppressWarnings(require(devtools))){ | |
install.packages("devtools") | |
require(devtools) | |
} | |
install_github("tdhock/requireGitHub") | |
require(requireGitHub) | |
} | |
requireGitHub(vers) | |
}else{# it is from a CRAN-like repos. | |
if(!suppressWarnings(require(pkg, character.only=TRUE))){ | |
install.packages(pkg) | |
} | |
pkg_ok_have(pkg, vers, packageVersion(pkg)) | |
library(pkg, character.only=TRUE) | |
} | |
} | |
} | |
works_with_R( | |
"3.3.1", | |
httr="1.0.0", | |
"Rdatatable/data.table@2b092fbae4380acac66baf923436fe796ec823d8") | |
devtools::session_info() | |
download.xzcat.fread <- function(u){ | |
request <- GET(u) | |
stop_for_status(request) | |
f <- sub(".*/", "", u) | |
writeBin(content(request), f) | |
cmd <- paste("xzcat", f) | |
fread(cmd, verbose=TRUE) | |
} | |
download.xzcat.fread("https://gist.github.com/tdhock/67f8507fee522343cc813a2affcb9d37/raw/7ca64af99e0fdb5c8e498d3c247fb364cb7364cc/small_fread_ok.txt.xz") | |
download.xzcat.fread("https://gist.github.com/tdhock/67f8507fee522343cc813a2affcb9d37/raw/7ca64af99e0fdb5c8e498d3c247fb364cb7364cc/big_fread_crashes.txt.xz") |
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
### Write down what package versions work with your R code, and | |
### attempt to download and load those packages. The first argument is | |
### the version of R that you used, e.g. "3.0.2" and then the rest of | |
### the arguments are package versions. For | |
### CRAN/Bioconductor/R-Forge/etc packages, write | |
### e.g. RColorBrewer="1.0.5" and if RColorBrewer is not installed | |
### then we use install.packages to get the most recent version, and | |
### warn if the installed version is not the indicated version. For | |
### GitHub packages, write "user/repo@commit" | |
### e.g. "tdhock/animint@f877163cd181f390de3ef9a38bb8bdd0396d08a4" and | |
### we use install_github to get it, if necessary. | |
works_with_R <- function(Rvers,...){ | |
pkg_ok_have <- function(pkg,ok,have){ | |
stopifnot(is.character(ok)) | |
if(!as.character(have) %in% ok){ | |
warning("works with ",pkg," version ", | |
paste(ok,collapse=" or "), | |
", have ",have) | |
} | |
} | |
pkg_ok_have("R",Rvers,getRversion()) | |
pkg.vers <- list(...) | |
for(pkg.i in seq_along(pkg.vers)){ | |
vers <- pkg.vers[[pkg.i]] | |
pkg <- if(is.null(names(pkg.vers))){ | |
"" | |
}else{ | |
names(pkg.vers)[[pkg.i]] | |
} | |
if(pkg == ""){# Then it is from GitHub. | |
## suppressWarnings is quieter than quiet. | |
if(!suppressWarnings(require(requireGitHub))){ | |
## If requireGitHub is not available, then install it using | |
## devtools. | |
if(!suppressWarnings(require(devtools))){ | |
install.packages("devtools") | |
require(devtools) | |
} | |
install_github("tdhock/requireGitHub") | |
require(requireGitHub) | |
} | |
requireGitHub(vers) | |
}else{# it is from a CRAN-like repos. | |
if(!suppressWarnings(require(pkg, character.only=TRUE))){ | |
install.packages(pkg) | |
} | |
pkg_ok_have(pkg, vers, packageVersion(pkg)) | |
library(pkg, character.only=TRUE) | |
} | |
} | |
} | |
works_with_R( | |
"3.4.1", | |
httr="1.3.1", | |
"Rdatatable/data.table@a869907b2ca0e1df2809027d1a6450c610d2704f") | |
devtools::session_info() | |
download.xzcat.fread <- function(u){ | |
request <- GET(u) | |
stop_for_status(request) | |
f <- sub(".*/", "", u) | |
writeBin(content(request), f) | |
cmd <- paste("xzcat", f) | |
fread(cmd, verbose=TRUE) | |
} | |
download.xzcat.fread("https://gist.github.com/tdhock/67f8507fee522343cc813a2affcb9d37/raw/7ca64af99e0fdb5c8e498d3c247fb364cb7364cc/small_fread_ok.txt.xz") | |
download.xzcat.fread("https://gist.github.com/tdhock/67f8507fee522343cc813a2affcb9d37/raw/7ca64af99e0fdb5c8e498d3c247fb364cb7364cc/big_fread_crashes.txt.xz") | |
system("xzcat big_fread_crashes.txt.xz | nl | tail") |
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
### Write down what package versions work with your R code, and | |
### attempt to download and load those packages. The first argument is | |
### the version of R that you used, e.g. "3.0.2" and then the rest of | |
### the arguments are package versions. For | |
### CRAN/Bioconductor/R-Forge/etc packages, write | |
### e.g. RColorBrewer="1.0.5" and if RColorBrewer is not installed | |
### then we use install.packages to get the most recent version, and | |
### warn if the installed version is not the indicated version. For | |
### GitHub packages, write "user/repo@commit" | |
### e.g. "tdhock/animint@f877163cd181f390de3ef9a38bb8bdd0396d08a4" and | |
### we use install_github to get it, if necessary. | |
works_with_R <- function(Rvers,...){ | |
pkg_ok_have <- function(pkg,ok,have){ | |
stopifnot(is.character(ok)) | |
if(!as.character(have) %in% ok){ | |
warning("works with ",pkg," version ", | |
paste(ok,collapse=" or "), | |
", have ",have) | |
} | |
} | |
pkg_ok_have("R",Rvers,getRversion()) | |
pkg.vers <- list(...) | |
for(pkg.i in seq_along(pkg.vers)){ | |
vers <- pkg.vers[[pkg.i]] | |
pkg <- if(is.null(names(pkg.vers))){ | |
"" | |
}else{ | |
names(pkg.vers)[[pkg.i]] | |
} | |
if(pkg == ""){# Then it is from GitHub. | |
## suppressWarnings is quieter than quiet. | |
if(!suppressWarnings(require(requireGitHub))){ | |
## If requireGitHub is not available, then install it using | |
## devtools. | |
if(!suppressWarnings(require(devtools))){ | |
install.packages("devtools") | |
require(devtools) | |
} | |
install_github("tdhock/requireGitHub") | |
require(requireGitHub) | |
} | |
requireGitHub(vers) | |
}else{# it is from a CRAN-like repos. | |
if(!suppressWarnings(require(pkg, character.only=TRUE))){ | |
install.packages(pkg) | |
} | |
pkg_ok_have(pkg, vers, packageVersion(pkg)) | |
library(pkg, character.only=TRUE) | |
} | |
} | |
} | |
works_with_R( | |
"3.4.1", | |
httr="1.3.1", | |
"Rdatatable/data.table@a869907b2ca0e1df2809027d1a6450c610d2704f") | |
devtools::session_info() | |
download.xzcat.fread <- function(u){ | |
request <- GET(u) | |
stop_for_status(request) | |
f <- sub(".*/", "", u) | |
writeBin(content(request), f) | |
cmd <- paste("xzcat", f) | |
fread(cmd, verbose=TRUE) | |
} | |
dt <- download.xzcat.fread("https://gist.github.com/tdhock/67f8507fee522343cc813a2affcb9d37/raw/1b698b2d43575b6f885364d551ff63bf6ccab94d/bigger.txt.xz") | |
system("xzcat bigger.txt.xz | nl | grep ^691260[0-9]") | |
system("xzcat bigger.txt.xz | nl | tail") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment