diff --git a/DESCRIPTION b/DESCRIPTION index 8a50098f..06e7a5c0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 1.7.1.9049 +Version: 1.7.1.9050 Date: 2021-10-05 Title: Antimicrobial Resistance Data Analysis Description: Functions to simplify and standardise antimicrobial resistance (AMR) diff --git a/NEWS.md b/NEWS.md index ba9bf692..2ba31ad1 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# `AMR` 1.7.1.9049 +# `AMR` 1.7.1.9050 ## Last updated: 5 October 2021 ### Breaking changes diff --git a/R/atc_online.R b/R/atc_online.R index 3741c757..87a9fde0 100644 --- a/R/atc_online.R +++ b/R/atc_online.R @@ -138,15 +138,21 @@ atc_online_property <- function(atc_code, atc_url <- sub("%s", atc_code[i], atc_url, fixed = TRUE) if (property == "groups") { - tbl <- read_html(atc_url) %pm>% - html_node("#content") %pm>% - html_children() %pm>% - html_node("a") + out <- tryCatch( + read_html(atc_url) %pm>% + html_node("#content") %pm>% + html_children() %pm>% + html_node("a"), + error = function(e) NULL) + if (is.null(out)) { + message_("Connection to ", atc_url, " failed.") + return(rep(NA, length(atc_code))) + } # get URLS of items - hrefs <- tbl %pm>% html_attr("href") + hrefs <- out %pm>% html_attr("href") # get text of items - texts <- tbl %pm>% html_text() + texts <- out %pm>% html_text() # select only text items where URL like "code=" texts <- texts[grepl("?code=", tolower(hrefs), fixed = TRUE)] # last one is antibiotics, skip it @@ -154,15 +160,21 @@ atc_online_property <- function(atc_code, returnvalue <- c(list(texts), returnvalue) } else { - tbl <- read_html(atc_url) %pm>% - html_nodes("table") %pm>% - html_table(header = TRUE) %pm>% - as.data.frame(stringsAsFactors = FALSE) + out <- tryCatch( + read_html(atc_url) %pm>% + html_nodes("table") %pm>% + html_table(header = TRUE) %pm>% + as.data.frame(stringsAsFactors = FALSE), + error = function(e) NULL) + if (is.null(out)) { + message_("Connection to ", atc_url, " failed.") + return(rep(NA, length(atc_code))) + } # case insensitive column names - colnames(tbl) <- gsub("^atc.*", "atc", tolower(colnames(tbl))) + colnames(out) <- gsub("^atc.*", "atc", tolower(colnames(out))) - if (length(tbl) == 0) { + if (length(out) == 0) { warning_("ATC not found: ", atc_code[i], ". Please check ", atc_url, ".", call = FALSE) returnvalue[i] <- NA next @@ -170,15 +182,15 @@ atc_online_property <- function(atc_code, if (property %in% c("atc", "name")) { # ATC and name are only in first row - returnvalue[i] <- tbl[1, property] + returnvalue[i] <- out[1, property] } else { - if (!"adm.r" %in% colnames(tbl) | is.na(tbl[1, "adm.r"])) { + if (!"adm.r" %in% colnames(out) | is.na(out[1, "adm.r"])) { returnvalue[i] <- NA next } else { - for (j in seq_len(nrow(tbl))) { - if (tbl[j, "adm.r"] == administration) { - returnvalue[i] <- tbl[j, property] + for (j in seq_len(nrow(out))) { + if (out[j, "adm.r"] == administration) { + returnvalue[i] <- out[j, property] } } } diff --git a/R/mo.R b/R/mo.R index c6e55cb8..a4fc7989 100755 --- a/R/mo.R +++ b/R/mo.R @@ -803,7 +803,7 @@ exec_as.mo <- function(x, perl = TRUE)), uncertainty = -1) next } - if (x_backup_without_spp[i] %like_case% "haemoly.*strep") { + if (x_backup_without_spp[i] %like_case% "ha?emoly.*strep") { # Haemolytic streptococci in different languages x[i] <- lookup(mo == "B_STRPT_HAEM", uncertainty = -1) next diff --git a/data-raw/AMR_latest.tar.gz b/data-raw/AMR_latest.tar.gz index e8b15c52..0a0107c9 100644 Binary files a/data-raw/AMR_latest.tar.gz and b/data-raw/AMR_latest.tar.gz differ diff --git a/data-raw/whonet_bugfixes.R b/data-raw/whonet_bugfixes.R index 11ebbc0e..41b45eec 100644 --- a/data-raw/whonet_bugfixes.R +++ b/data-raw/whonet_bugfixes.R @@ -7,5 +7,5 @@ microorganisms.codes[which(microorganisms.codes$code == "ENT"), "mo"] <- as.mo(" microorganisms.codes[which(microorganisms.codes$code == "STR"), "mo"] <- as.mo("streptococcus") microorganisms.codes[which(microorganisms.codes$code == "CDF"), "mo"] <- as.mo("clostridium difficile") microorganisms.codes[which(microorganisms.codes$code == "HA-"), "mo"] <- as.mo("haemophilus influenzae") -usethis::use_data(microorganisms.codes, overwrite = TRUE) +usethis::use_data(microorganisms.codes, overwrite = TRUE, version = 2) rm(microorganisms.codes) diff --git a/data/microorganisms.codes.rda b/data/microorganisms.codes.rda index d84f94cb..81edf0fa 100644 Binary files a/data/microorganisms.codes.rda and b/data/microorganisms.codes.rda differ diff --git a/docs/articles/datasets.html b/docs/articles/datasets.html index a0913a93..370b2957 100644 --- a/docs/articles/datasets.html +++ b/docs/articles/datasets.html @@ -44,7 +44,7 @@ AMR (for R) - 1.7.1.9049 + 1.7.1.9050 diff --git a/docs/news/index.html b/docs/news/index.html index 103202a9..601b428b 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -92,7 +92,7 @@ AMR (for R) - 1.7.1.9049 + 1.7.1.9050 @@ -240,9 +240,9 @@ Source: NEWS.md -
-

- Unreleased AMR 1.7.1.9049

+
+

+ Unreleased AMR 1.7.1.9050

Last updated: 5 October 2021 diff --git a/docs/reference/ab_property.html b/docs/reference/ab_property.html index 6cd712c6..d8bd4baa 100644 --- a/docs/reference/ab_property.html +++ b/docs/reference/ab_property.html @@ -93,7 +93,7 @@ AMR (for R) - 1.7.1.9040 + 1.7.1.9050

diff --git a/docs/reference/index.html b/docs/reference/index.html index 06f72d4b..c9e1f8b7 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -92,7 +92,7 @@ AMR (for R) - 1.7.1.9040 + 1.7.1.9050
@@ -478,7 +478,7 @@

microorganisms.codes

-

Data Set with 5,605 Common Microorganism Codes

+

Data Set with 5,604 Common Microorganism Codes

diff --git a/docs/reference/microorganisms.codes.html b/docs/reference/microorganisms.codes.html index 5479dd3c..61e0c101 100644 --- a/docs/reference/microorganisms.codes.html +++ b/docs/reference/microorganisms.codes.html @@ -6,7 +6,7 @@ -Data Set with 5,605 Common Microorganism Codes — microorganisms.codes • AMR (for R) +Data Set with 5,604 Common Microorganism Codes — microorganisms.codes • AMR (for R) @@ -48,7 +48,7 @@ - + @@ -93,7 +93,7 @@ AMR (for R) - 1.7.1.9030 + 1.7.1.9050
@@ -237,7 +237,7 @@
@@ -251,7 +251,7 @@

Format

-

A data.frame with 5,605 observations and 2 variables: