On 2020-06-19 16:07 -0500, Ana Marija wrote: > HI Rasmus, > > I tried it: > > library(base) > > > r <- readRDS(paste0(population.name, ".rds")) > Error in gzfile(file, "rb") : cannot open the connection > In addition: Warning message: > In gzfile(file, "rb") : > cannot open compressed file '1000GENOMES:phase_3:KHV.rds', probable > reason 'No such file or directory'
Because I run my script again and again after every little small change using the program entr[1] as opposed to using Emacs Speaks Statistics or RStudio, I find it useful to save partial outputs in rds files, but it also make sense to not call ensembl.org again and again ... Right, so you would run the commented bit before that first, then save the output list to the rds to not send too many requests to the list. I have attached my rds here. files <- c("1g.txt", "1n.txt") files <- lapply(files, readLines) server <- "http://rest.ensembl.org" population.name <- "1000GENOMES:phase_3:KHV" ext <- apply(expand.grid(files), 1, function(x) { return(paste0(server, "/ld/human/pairwise/", x[1], "/", x[2], "?population_name=", population.name)) }) r <- lapply(ext, function(x) { httr::GET(x, httr::content_type("application/json")) }) names(r) <- ext file <- paste0(population.name, ".rds") saveRDS(object=r, compress="xz", file=file) # <--- Then save the list here for another time! # r <- readRDS(paste0(population.name, ".rds")) # Read it back like this r <- sapply(r, function(x) { x <- jsonlite::fromJSON(jsonlite::toJSON(httr::content(x))) length(x) }) names(r) <- NULL r [1] http://eradman.com/entrproject/
signature.asc
Description: PGP signature
______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.