Skip to content

Commit

Permalink
Fix the RCurl::url.exists() to httr::http_error() transition
Browse files Browse the repository at this point in the history
  • Loading branch information
lcolladotor committed May 6, 2023
1 parent 2c3d29e commit 82f45ce
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 26 deletions.
26 changes: 16 additions & 10 deletions R/file_retrieve.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,23 @@ file_retrieve <-
## In case the url is a local file, there's no need to cache it then
if (file.exists(url)) {
return(url)
} else if (http_error(url)) {
if (!grepl("tcga\\.recount_pred|gtex\\.recount_pred", url)) {
warning("The 'url' <",
url,
"> does not exist or is not available.",
call. = FALSE
)
} else {
url_failed <- tryCatch(
http_error(url),
error = function(e) { return (TRUE)}
)
if (url_failed) {
if (!grepl("tcga\\.recount_pred|gtex\\.recount_pred", url)) {
warning("The 'url' <",
url,
"> does not exist or is not available.",
call. = FALSE
)
}
res <- as.character(NA)
names(res) <- names(url)
return(res)
}
res <- as.character(NA)
names(res) <- names(url)
return(res)
}

if (!methods::is(bfc, "BiocFileCache")) {
Expand Down
41 changes: 25 additions & 16 deletions R/project_homes.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,10 @@ project_homes <-
homes <- getOption(option_name)
if (!is.null(homes)) {
return(homes)
}

## Construct the URL for the homes_index file
homes_url <-
paste(recount3_url, organism, "homes_index", sep = "/")
if (!http_error(homes_url)) {
homes_from_url <- readLines(homes_url)

## Cache the result for the resulting organism so we don't need
## to check this again in this R session
options_list <- list(homes_from_url)
names(options_list) <- option_name
options(options_list)
}

## Return result found
return(homes_from_url)
} else if (recount3_url == "http://snaptron.cs.jhu.edu/data/temp/recount3") {
## For the recount3 test case
if (recount3_url == "http://snaptron.cs.jhu.edu/data/temp/recount3") {
if (organism == "mouse") {
return("data_sources/sra")
} else if (organism == "human") {
Expand All @@ -68,6 +55,28 @@ project_homes <-
)
)
}
}

url_failed <- tryCatch(
http_error(homes_url),
error = function(e) { return (TRUE)}
)


## Construct the URL for the homes_index file
homes_url <-
paste(recount3_url, organism, "homes_index", sep = "/")
if (!url_failed) {
homes_from_url <- readLines(homes_url)

## Cache the result for the resulting organism so we don't need
## to check this again in this R session
options_list <- list(homes_from_url)
names(options_list) <- option_name
options(options_list)

## Return result found
return(homes_from_url)
} else if (!file.exists(recount3_url)) {
stop(
"'recount3_url' is not a valid supported URL since it's missing the URL/<organism>/homes_index text file or 'recount3_url' is not an existing directory in your file system.",
Expand Down

0 comments on commit 82f45ce

Please sign in to comment.