Skip to content

Commit aa3cb84

Browse files
committed
fix R CMD check error
1 parent fb95997 commit aa3cb84

File tree

5 files changed

+29
-27
lines changed

5 files changed

+29
-27
lines changed

R/fda_drugs.R

+20-11
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fda_drugs_file <- function(url = NULL, force,
4949
prefix = "fda_drugs_data",
5050
ext = "zip",
5151
name = "Drugs@FDA data",
52-
dir = dir,
52+
dir = dir,
5353
method = "base", mode = "wb",
5454
arg = arg, call = call
5555
)
@@ -59,15 +59,24 @@ fda_drugs_url <- function(url = NULL,
5959
arg = rlang::caller_arg(url),
6060
call = rlang::caller_env()) {
6161
if (!is.null(url)) return(url) # styler: off
62-
assert_internet(call = call)
63-
url <- sprintf(
64-
"%s/drugs/drug-approvals-and-databases/drugsfda-data-files",
65-
fda_host("www")
66-
)
67-
cli::cli_inform(c(">" = "Reading html: {.url {url}}"))
68-
html <- xml2::read_html(url)
69-
node <- rvest::html_element(html, "[data-entity-substitution]")
70-
if (inherits(node, "xml_missing")) {
62+
host <- fda_host("www")
63+
if (curl::has_internet()) {
64+
url <- sprintf(
65+
"%s/drugs/drug-approvals-and-databases/drugsfda-data-files",
66+
host
67+
)
68+
node <- tryCatch(
69+
{
70+
html <- xml2::read_html(url)
71+
cli::cli_inform(c(">" = "Reading html: {.url {url}}"))
72+
rvest::html_element(html, "[data-entity-substitution]")
73+
},
74+
error = function(cnd) NULL
75+
)
76+
} else {
77+
node <- NULL
78+
}
79+
if (is.null(node) || inherits(node, "xml_missing")) {
7180
# cli::cli_abort(c(
7281
# "Cannot determine the url of {.field Drugs@FDA} file",
7382
# i = "try to provide {.arg {arg}} manually"
@@ -77,5 +86,5 @@ fda_drugs_url <- function(url = NULL,
7786
cli::cat_line(rvest::html_text(node))
7887
href <- rvest::html_attr(node, "href")
7988
}
80-
paste0(fda_host("www"), href)
89+
paste0(host, href)
8190
}

R/meta.R

+6-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#' information about all records' metadata in the FAERS Quarterly Data Extract
88
#' Files Site, bypassing the cache.
99
#' @param internal A boolean value. It determines whether to use the internal
10-
#' data associated with the package when no cached file is available.
10+
#' data associated with the package.
1111
#' @return A [data.table][data.table::data.table] reporting years, period,
1212
#' quarter, and file urls and file sizes.
1313
#' @examples
@@ -26,19 +26,16 @@ faers_meta <- function(force = FALSE, internal = !curl::has_internet()) {
2626
}
2727

2828
faers_meta_cache_read <- function(internal = FALSE) {
29-
file <- faers_meta_cache_file()
30-
if (file.exists(file)) {
29+
if (internal) {
30+
out <- load_data("faers_meta_data")
31+
msg <- "Using internal FAERS metadata"
32+
} else if (file.exists(file <- faers_meta_cache_file())) {
3133
out <- readRDS(file)
3234
msg <- "Using FAERS metadata from cached {.file {file}}"
3335
# save the data in the cached environment for the usage of next time
3436
# like faers_available()
3537
} else {
36-
if (internal) {
37-
out <- load_data("faers_meta_data")
38-
msg <- "Using internal FAERS metadata"
39-
} else {
40-
return(NULL)
41-
}
38+
return(NULL)
4239
}
4340
cli::cli_inform(c(">" = msg, " " = "Snapshot time: {out$date}"))
4441
out$data

man/faers_available.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/faers_meta.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/FAERS-Pharmacovigilance.Rmd

+1-5
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,12 @@ If it doesn't exist, the internal will parse metadata in
8686
<`r sprintf("%s/extensions/FPD-QDE-FAERS/FPD-QDE-FAERS.html",
8787
faers:::fda_host("fis"))`>
8888

89-
```{r}
89+
```{r eval=FALSE}
9090
faers_meta()
9191
```
9292

9393
An metadata copy was associated with the package, just set `internal = TRUE`.
94-
However, this copy will only be used if the cached file on your computer cannot
95-
be found as the cached file on your computer should be more up-to-date than this
96-
metadata copy.
9794
```{r}
98-
faers_clearcache("metadata")
9995
faers_meta(internal = TRUE)
10096
```
10197

0 commit comments

Comments
 (0)