Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Suggests:
plot.matrix,
usethis,
vcr (>= 0.6.0)
RoxygenNote: 7.3.2
RoxygenNote: 7.3.3
VignetteBuilder: knitr
Config/testthat/edition: 3
Config/testthat/parallel: true
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## NEW FEATURES

* `bcpc_query()` now also looks for derivatives (esters and salts) of active compounds
* Added a new function `chembl_img()` for downloading SVG images from ChEMBL.
* Added a new function `db_download_chembl()` for downloading ChEMBL for fully offline access.

Expand Down
31 changes: 24 additions & 7 deletions R/bcpc.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#' formerly known as Alan Woods Compendium of Pesticide Common Names
#' @import xml2
#'
#' @param query character; search string
#' @param query character; search string
#' @param from character; type of input ('cas' or 'name')
#' @param verbose logical; print message during processing to console?
#' @param ... additional arguments to internal utility functions
#' @param type deprecated
#' @return A list of eight entries: common-name, status, preferred IUPAC Name,
#' @return A list of eleven entries: common-name, status, preferred IUPAC Name,
#' IUPAC Name, cas, formula, activity, subactivity, inchikey, inchi and source
#' url.
#' @note for from = 'cas' only the first matched link is returned.
Expand Down Expand Up @@ -196,6 +196,7 @@ build_bcpc_idx <- function(verbose = getOption("verbose"), force_build = FALSE)
if (verbose) message("Building index. ", appendLF = FALSE)
idx1_url <- "https://pesticidecompendium.bcpc.org/index_rn.html"
idx4_url <- "https://pesticidecompendium.bcpc.org/index_cn.html"
idxd_url <- "https://pesticidecompendium.bcpc.org/derivatives/index-derivatives.html"
res1 <- try(httr::RETRY("GET",
idx1_url,
httr::user_agent(webchem_url()),
Expand Down Expand Up @@ -225,10 +226,10 @@ build_bcpc_idx <- function(verbose = getOption("verbose"), force_build = FALSE)
config = httr::config(accept_encoding = "identity"),
terminate_on = 404,
quiet = TRUE), silent= TRUE)
if (inherits(res4, "try-error")) {
if (verbose) webchem_message("service_down")
return(NA)
}
if (inherits(res4, "try-error")) {
if (verbose) webchem_message("service_down")
return(NA)
}
idx4 <- read_html(res4)
n <- xml_find_all(idx4, "//a")
names <- xml_text(n)
Expand All @@ -238,7 +239,23 @@ build_bcpc_idx <- function(verbose = getOption("verbose"), force_build = FALSE)
links <- links[!rm]
idx4 <- data.frame(names = NA, links = links, linknames = names,
source = "cn", stringsAsFactors = FALSE)
bcpc_idx <- rbind(bcpc_idx, idx4)
resd <- try(httr::RETRY("GET",
idxd_url,
httr::user_agent(webchem_url()),
config = httr::config(accept_encoding = "identity"),
terminate_on = 404,
quiet = TRUE), silent= TRUE)
idxd <- read_html(resd)
n <- xml_find_all(idxd, "//a")
names <- xml_text(n)
rm <- names == "" | names == "Index of Ester and Salt Derivatives"
names <- names[!rm]
links <- xml_attr(n, "href")
links <- links[!rm]
idxd <- data.frame(names = NA, links = paste0("derivatives/", links), linknames = names,
source = "cn", stringsAsFactors = FALSE)

bcpc_idx <- rbind(bcpc_idx, idx4, idxd)

# fix encoding
ln <- bcpc_idx$linknames
Expand Down
2 changes: 1 addition & 1 deletion man/bcpc_query.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions tests/testthat/test-bcpc.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ test_that("BCPC pesticide compendium, name", {
skip_on_cran()
skip_if_not(up, "BCPC pesticide compendium is down")

comps <- c("Fluazinam", "S-Metolachlor", "balloon", NA)
comps <- c("Fluazinam", "S-Metolachlor", "balloon", NA, "Triclopyr-butotyl")
o1 <- bcpc_query(comps, from = "name")

expect_type(o1, "list")
expect_equal(length(o1), 4)
expect_equal(length(o1), 5)
expect_type(o1[[1]], "list")
expect_type(o1[[2]], "list")
expect_equal(o1[[3]], NA)
Expand All @@ -38,6 +38,7 @@ test_that("BCPC pesticide compendium, name", {
expect_equal(length(o1[["S-Metolachlor"]]$inchikey), 2)
expect_equal(length(o1[["S-Metolachlor"]]$inchi), 2)
expect_equal(length(o1[["Fluazinam"]]), 11)
expect_equal(length(o1[["Triclopyr-butotyl"]]), 11)
})


Expand Down