diff --git a/DESCRIPTION b/DESCRIPTION index cff3acf..0d911ea 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: ECOTOXr Type: Package Title: Download and Extract Data from US EPA's ECOTOX Database -Version: 1.0.8 -Date: 2024-01-01 +Version: 1.0.9 +Date: 2024-01-07 Authors@R: c(person("Pepijn", "de Vries", role = c("aut", "cre", "dtc"), email = "pepijn.devries@outlook.com", comment = c(ORCID = "0000-0002-7961-6646"))) @@ -16,13 +16,13 @@ Description: The US EPA ECOTOX database is a freely available database in R. To this end, all raw tables are downloaded from the EPA website and stored in a local SQLite database. Depends: - R (>= 3.5.0), + R (>= 4.1.0), RSQLite (>= 2.3.4) Imports: crayon (>= 1.5.2), dbplyr (>= 2.4.0), dplyr (>= 1.1.4), - httr (>= 1.4.7), + httr2 (>= 1.0.0), jsonlite (>= 1.8.8), lifecycle (>= 1.0.4), purrr (>= 1.0.2), diff --git a/NAMESPACE b/NAMESPACE index b0779ed..38371a1 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -12,11 +12,12 @@ S3method(as.list,cas) S3method(c,cas) S3method(format,cas) S3method(print,cas) -export("%>%") export(as.cas) export(build_ecotox_sqlite) export(cas) export(check_ecotox_availability) +export(check_ecotox_build) +export(check_ecotox_version) export(cite_ecotox) export(dbConnectEcotox) export(dbDisconnectEcotox) @@ -38,7 +39,6 @@ importFrom(RSQLite,dbConnect) importFrom(RSQLite,dbDisconnect) importFrom(RSQLite,dbExecute) importFrom(RSQLite,dbWriteTable) -importFrom(dplyr,"%>%") importFrom(dplyr,collect) importFrom(dplyr,inner_join) importFrom(dplyr,left_join) @@ -46,4 +46,5 @@ importFrom(dplyr,select) importFrom(dplyr,sql) importFrom(dplyr,tbl) importFrom(lifecycle,badge) +importFrom(rlang,"!!!") importFrom(rlang,":=") diff --git a/NEWS.md b/NEWS.md index 48d0920..85329ee 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,11 @@ -ECOTOXr v1.0.8 (Release date: 2024-01-01) +ECOTOXr v1.0.9 (Release date: 2024-01-07) ------------- + * switched from the 'magrittr' pipe operator ('%>%') + to R's native pipe operator ('|>') + * switched from 'httr' to 'httr2' dependency + * Added functions to check the local build + and its version * Fix in database build routine * Fix in manual to pass CRAN checks * Explicit mentioning of required versions diff --git a/R/database_access.r b/R/database_access.r index 6952eaf..42053ec 100644 --- a/R/database_access.r +++ b/R/database_access.r @@ -181,3 +181,129 @@ list_ecotox_fields <- function(which = c("default", "extended", "full", "all"), "dose_response_links", "dose_stat_method_codes"))] return(result) } + +#' Check the locally build database for validity +#' +#' `r lifecycle::badge('stable')` Performs some simple tests to check whether the +#' locally built database is not corrupted. +#' +#' For now this function tests if all expected tables are present in the locally built +#' database. Note that in later release of the database some tables were added. Therefore +#' for older builds this function might return `FALSE` whereas it is actually just fine +#' (just out-dated). +#' +#' Furthermore, this function tests if all tables contain one or more records. Obviously, +#' this is no guarantee that the database is valid, but it is a start. +#' +#' More tests may be added in future releases. +#' @inheritParams dbConnectEcotox +#' @returns Returns an indicative logical value whether the database is not corrupted. +#' `TRUE` indicates the database is most likely OK. `FALSE` indicates that something might +#' be wrong. Additional messages (when `FALSE`) are included as attributes containing hints +#' on the outcoming of the tests. See also the 'details' section. +#' @rdname check_ecotox_build +#' @name check_ecotox_build +#' @examples +#' \dontrun{ +#' check_ecotox_build() +#' } +#' @author Pepijn de Vries +#' @export +check_ecotox_build <- function(path = get_ecotox_path(), version, ...) { + validity <- TRUE + con <- tryCatch({ + dbConnectEcotox(path, version, ...) + }, error = function(e) NULL) + if (is.null(con)) { + validity <- FALSE + attr(validity, "reasons") <- + c(attr(validity, "reasons"), "Cannot connect with 'target' and 'version'.") + } else { + tables <- RSQLite::dbListTables(con) + missing_tables <- .db_specs$table[!.db_specs$table %in% tables] + if (length(missing_tables) > 0) { + validity <- FALSE + attr(validity, "reasons") <- + c(attr(validity, "reasons"), + sprintf("The following tables were missing: %s", + paste0(missing_tables, collapse = "; "))) + } else { + for (tab in tables) { + n <- dplyr::tbl(con, tab) |> dplyr::summarise(n = dplyr::n()) |> dplyr::pull("n") + if (n == 0) { + validity <- FALSE + attr(validity, "reasons") <- + c(attr(validity, "reasons"), + "One or more tables have no records") + break + } + } + } + dbDisconnect(con) + } + return (validity) +} + +#' Check if the locally build database is up to date +#' +#' `r lifecycle::badge('stable')` Checks the version of the database available on-line +#' from the EPA against the specified version (latest by default) of the database build +#' locally. Returns `TRUE` when they are the same. +#' +#' @inheritParams get_ecotox_sqlite_file +#' @param verbose A `logical` value. If true messages are shown on the console reporting +#' on the check. +#' @returns Returns a `logical` value invisibly indicating whether the locally build +#' is up to date with the latest release by the EPA. +#' @rdname check_ecotox_version +#' @name check_ecotox_version +#' @examples +#' \dontrun{ +#' check_ecotox_version() +#' } +#' @author Pepijn de Vries +#' @export +check_ecotox_version <- function(path = get_ecotox_path(), version, verbose = TRUE) { + u <- + get_ecotox_url() |> + basename() |> + stringr::str_extract("(?<=^ecotox_ascii_)(.*?)(?=\\.zip$)") |> + as.Date(format = "%m_%d_%Y") + + available <- check_ecotox_availability(path) + if (!available) { + if (verbose) { + message(crayon::red( + "No databased present at the specified path" + )) + } + return(invisible(FALSE)) + } + f <- + get_ecotox_sqlite_file(path, version) |> + basename() |> + stringr::str_extract("(?<=^ecotox_ascii_)(.*?)(?=\\.sqlite$)") |> + as.Date(format = "%m_%d_%Y") + result <- f == u + if (verbose) { + if (result) { + message(crayon::green( + paste("The locally build database represents", + "the latest available EPA release", + format(f, format = "(%Y-%m-%d). You are up to date."), + sep = "\n"))) + } else if (f < u) { + message(crayon::red( + paste(format(f, "The locally build database (%Y-%m-%d) represents"), + format(u, "an older EPA release (%Y-%m-%d). Please download"), + "and build the latest relase if you.", + "wish to be up to date.", sep = "\n"))) + } else if (f > u) { + message(crayon::red( + paste(format(f, "You have installed a future release (%Y-%m-%d)"), + format(u, "of the EPA database (%Y-%m-%d). Are you a time"), + "traveller?", sep = "\n"))) + } + } + return(invisible(result)) +} \ No newline at end of file diff --git a/R/helpers.r b/R/helpers.r index 27164d8..93e1018 100644 --- a/R/helpers.r +++ b/R/helpers.r @@ -18,8 +18,8 @@ .data <- field <- terms <- table_mod <- NULL search_result <- - lapply(search, as.data.frame, strings.as.factors = F) %>% - dplyr::bind_rows(.id = "field") %>% + lapply(search, as.data.frame, strings.as.factors = F) |> + dplyr::bind_rows(.id = "field") |> dplyr::mutate( table = lapply(field, function(x) { switch( @@ -28,9 +28,9 @@ test_id = "tests", .db_specs$table[.db_specs$field_name %in% x]) }) - ) %>% - tidyr::unnest("table") %>% - dplyr::group_by(dplyr::across(dplyr::any_of(c("table", "field", "method")))) %>% + ) |> + tidyr::unnest("table") |> + dplyr::group_by(dplyr::across(dplyr::any_of(c("table", "field", "method")))) |> dplyr::summarise( where = { method <- tryCatch({.data$method[[1]]}, error = function(e) "contains") @@ -41,27 +41,27 @@ } else { stop("Sorry, specified search method is not implemented.") } - }) %>% - dplyr::group_by(table) %>% + }) |> + dplyr::group_by(table) |> dplyr::group_map(~{ dplyr::tibble( - tbl = list(tbl(dbcon, .x$table[[1]]) %>% dplyr::filter(!!sql(paste(sprintf("(%s)", .x$where), collapse = " AND ")))), + tbl = list(tbl(dbcon, .x$table[[1]]) |> dplyr::filter(!!sql(paste(sprintf("(%s)", .x$where), collapse = " AND ")))), table = .x$table[[1]] - )}, .keep = T) %>% - dplyr::bind_rows() %>% - dplyr::group_by(table_mod = gsub("_synonyms", "", table)) %>% + )}, .keep = T) |> + dplyr::bind_rows() |> + dplyr::group_by(table_mod = gsub("_synonyms", "", table)) |> dplyr::summarise( table = table_mod[[1]], tbl = if (length(tbl) > 1) { - tbl %>% - purrr::map(~{select(., dplyr::any_of("species_number"))}) %>% - purrr::reduce(~{dplyr::union(.x, .y)}) %>% + tbl |> + purrr::map(~{select(., dplyr::any_of("species_number"))}) |> + purrr::reduce(~{dplyr::union(.x, .y)}) |> list() } else { tbl - }) %>% - dplyr::group_by(dplyr::across(dplyr::any_of("table"))) %>% + }) |> + dplyr::group_by(dplyr::across(dplyr::any_of("table"))) |> dplyr::group_map(~{ #keep linking tables until result_ids are obtained my_tab <- ..1$tbl[[1]] @@ -76,35 +76,35 @@ if (nrow(referring) == 1) { foreign <- unlist(regmatches(referring$foreign_key, gregexpr("(?<=\\().+(?=\\))", referring$foreign_key, perl = T))) my_tab <- - my_tab %>% + my_tab |> left_join(tbl(dbcon, referring$table), by = structure(referring$field_name, names = foreign)) } else { stop("Sorry could not build a query for the search you have specified.") } } - dplyr::tibble(tbl = list(my_tab %>% select(dplyr::any_of(c("result_id", "test_id"))))) - }) %>% - dplyr::bind_rows() %>% - dplyr::group_by(result_available = tbl %>% - purrr::map(~ paste(sort(match(colnames(.), c("test_id", "result_id"))), collapse = "_")) %>% - unlist()) %>% + dplyr::tibble(tbl = list(my_tab |> select(dplyr::any_of(c("result_id", "test_id"))))) + }) |> + dplyr::bind_rows() |> + dplyr::group_by(result_available = tbl |> + purrr::map(~ paste(sort(match(colnames(.), c("test_id", "result_id"))), collapse = "_")) |> + unlist()) |> dplyr::group_map(~{ switch( .y$result_available, `1` = { - purrr::reduce(.x$tbl, ~{inner_join(.x, .y, by = "test_id")}) %>% - left_join(tbl(dbcon, "results"), by = "test_id") %>% + purrr::reduce(.x$tbl, ~{inner_join(.x, .y, by = "test_id")}) |> + left_join(tbl(dbcon, "results"), by = "test_id") |> select(dplyr::all_of(c("test_id", "result_id"))) }, `2` = { - purrr::reduce(.x$tbl, ~{inner_join(.x, .y, by = "result_id")}) %>% - left_join(tbl(dbcon, "results"), by = "result_id") %>% + purrr::reduce(.x$tbl, ~{inner_join(.x, .y, by = "result_id")}) |> + left_join(tbl(dbcon, "results"), by = "result_id") |> select(dplyr::all_of(c("test_id", "result_id"))) }, `1_2` = { purrr::reduce(.x$tbl, ~{inner_join(.x, .y, by = c("test_id", "result_id"))}) }) - }) %>% + }) |> purrr::reduce(~{inner_join(.x, .y, by = c("test_id", "result_id"))}) return(search_result) @@ -180,26 +180,26 @@ } if (length(join_params) > 0) { ## Create temp fields where forward slash is removed for joining with lookup values - lefties <- join_params %>% purrr::map_chr(~.$left_by) - lefties_repl <- lefties %>% purrr::map(~rlang::expr(REPLACE(!!rlang::sym(gsub("_temp$", "", .)), "/", ""))) + lefties <- join_params |> purrr::map_chr(~.$left_by) + lefties_repl <- lefties |> purrr::map(~rlang::expr(REPLACE(!!rlang::sym(gsub("_temp$", "", .)), "/", ""))) names(lefties_repl) <- lefties - result <- result %>% dplyr::mutate(!!!lefties_repl) + result <- result |> dplyr::mutate(!!!lefties_repl) for (i in seq_along(join_params)) { jp <- join_params[[i]] result <- - result %>% - left_join(tbl(dbcon, jp$right_table) %>% dplyr::rename(!!!jp$right_select), + result |> + left_join(tbl(dbcon, jp$right_table) |> dplyr::rename(!!!jp$right_select), by = structure(jp$right_by, names = jp$left_by)) } - result <- result %>% select(-dplyr::any_of(lefties)) - if (compute) result <- result %>% dplyr::compute() + result <- result |> select(-dplyr::any_of(lefties)) + if (compute) result <- result |> dplyr::compute() } return(result) } result <- search_result - if (compute) result <- result %>% dplyr::compute() + if (compute) result <- result |> dplyr::compute() ## start with results table as this is needed for obtaining dose link ids results_output <- union(output_fields$field[output_fields$table == "results"], "result_id") @@ -209,28 +209,28 @@ out_rename <- output_fields$table %in% dose_tables & !output_fields$field %in% c("test_id", "result_id") output_fields$new_field[out_rename] <- paste0("dose_link_", output_fields$field[out_rename]) result <- - result %>% - left_join(tbl(con, "dose_response_links"), "result_id") %>% - left_join(tbl(con, "dose_responses"), c("dose_resp_id", "test_id")) %>% - left_join(tbl(con, "dose_response_details"), "dose_resp_id") %>% - left_join(tbl(con, "doses"), c("dose_id", "test_id")) %>% - dplyr::rename_with(~paste0("dose_link_", .), !dplyr::any_of(c("test_id", "result_id"))) %>% - .process_lookups("dose_response_links") %>% + result |> + left_join(tbl(con, "dose_response_links"), "result_id") |> + left_join(tbl(con, "dose_responses"), c("dose_resp_id", "test_id")) |> + left_join(tbl(con, "dose_response_details"), "dose_resp_id") |> + left_join(tbl(con, "doses"), c("dose_id", "test_id")) |> + dplyr::rename_with(~paste0("dose_link_", .), !dplyr::any_of(c("test_id", "result_id"))) |> + .process_lookups("dose_response_links") |> .process_lookups("doses", "dose_link_") } if (any(c("media_characteristics", "organic_matter_type_codes") %in% output_fields_tables)) { foreigns <- .db_specs$field_name[.db_specs$table == "media_characteristics" & .db_specs$foreign_key != ""] result <- - result %>% - left_join(tbl(con, "media_characteristics"), "result_id") %>% + result |> + left_join(tbl(con, "media_characteristics"), "result_id") |> select(dplyr::any_of(union( colnames(result), union( foreigns, output_fields$field[output_fields$table == "media_characteristics"] ) - ))) %>% + ))) |> .process_lookups("media_characteristics") } @@ -238,12 +238,12 @@ table = gsub("\\(.*?\\)", "", .db_specs$foreign_key[.db_specs$foreign_key != "" & .db_specs$table == "results"]), field = .db_specs$field_name[.db_specs$foreign_key != "" & .db_specs$table == "results"] - ) %>% dplyr::filter(!table %in% c("tests", "results")) + ) |> dplyr::filter(!table %in% c("tests", "results")) results_output <- union(results_output, c("result_id", result_foreigns$field)) - result <- result %>% - left_join(tbl(con, "results") %>% - select(dplyr::any_of(union(c("result_id", "test_id"), results_output))) %>% + result <- result |> + left_join(tbl(con, "results") |> + select(dplyr::any_of(union(c("result_id", "test_id"), results_output))) |> dplyr::rename_with(function(x) paste0("result_", x), dplyr::any_of(c("created_date", "modified_date", "additional_comments"))), c("result_id", "test_id")) @@ -254,9 +254,9 @@ output_fields$new_field[output_fields$table == "results" & output_fields$field == "additional_comments"] <- "result_additional_comments" - if (compute) result <- result %>% dplyr::compute() + if (compute) result <- result |> dplyr::compute() - result <- result %>% .process_lookups("results") + result <- result |> .process_lookups("results") ## continue with linking all requested tables to the test data @@ -264,10 +264,10 @@ car_sel <- output_fields$table == "chemical_carriers" & !output_fields$field %in% c("carrier_id", "test_id") output_fields$new_field[car_sel] <- paste0("carrier_", output_fields$new_field[car_sel]) result <- - result %>% - left_join(tbl(con, "chemical_carriers") %>% + result |> + left_join(tbl(con, "chemical_carriers") |> dplyr::rename_with(~paste0("carrier_", .), !dplyr::any_of(c("carrier_id", "test_id"))), - "test_id") %>% + "test_id") |> select(dplyr::any_of(union( colnames(result), output_fields$new_field[output_fields$table == "chemical_carriers"] @@ -278,7 +278,7 @@ table = gsub("\\(.*?\\)", "", .db_specs$foreign_key[.db_specs$foreign_key != "" & .db_specs$table == "tests"]), field = .db_specs$field_name[.db_specs$foreign_key != "" & .db_specs$table == "tests"] - ) %>% dplyr::filter(!table %in% c("tests", "results")) + ) |> dplyr::filter(!table %in% c("tests", "results")) test_foreigns <- test_foreigns[test_foreigns$table %in% output_fields$table,,drop = F] test_foreigns$foreign <- .db_specs$field_name[.db_specs$primary_key != ""][ @@ -287,9 +287,9 @@ required_test_fields <- union(output_fields$field[output_fields$table == "tests"], test_foreigns$field) - result <- result %>% - left_join(tbl(con, "tests") %>% - select(dplyr::any_of(union("test_id", required_test_fields))) %>% + result <- result |> + left_join(tbl(con, "tests") |> + select(dplyr::any_of(union("test_id", required_test_fields))) |> dplyr::rename_with(function(x) paste0("test_", x), dplyr::any_of(c("created_date", "modified_date", "additional_comments"))), "test_id") @@ -303,27 +303,27 @@ if (any(c("species", "species_synonyms") %in% output_fields_tables)) { species_fields <- output_fields$field[output_fields$table == "species"] species_syn_fields <- output_fields$field[output_fields$table == "species_synonyms"] - result <- result %>% + result <- result |> left_join( - tbl(con, "species") %>% select(union(species_fields, "species_number")), + tbl(con, "species") |> select(union(species_fields, "species_number")), "species_number") if (length(species_syn_fields) > 0) { output_fields$new_field[output_fields$table == "species_synonyms" & output_fields$field == "latin_name"] <- "species_synonyms" spec_syns <- - tbl(con, "species_synonyms") %>% + tbl(con, "species_synonyms") |> select(union(species_syn_fields, "species_number")) if ("species_synonyms" %in% output_fields$table) { - spec_syns <- spec_syns %>% dplyr::rename(species_synonyms = "latin_name") + spec_syns <- spec_syns |> dplyr::rename(species_synonyms = "latin_name") } - result <- result %>% left_join(spec_syns, "species_number") + result <- result |> left_join(spec_syns, "species_number") } } if (!is.null(list(...)$group_by_results) && list(...)$group_by_results && "species_synonyms" %in% colnames(result)) { - result <- result %>% - dplyr::group_by(dplyr::across(!dplyr::any_of("species_synonyms"))) %>% - dplyr::summarise(dplyr::across(dplyr::any_of("species_synonyms"), ~GROUP_CONCAT(., "|")), .groups = "keep") %>% + result <- result |> + dplyr::group_by(dplyr::across(!dplyr::any_of("species_synonyms"))) |> + dplyr::summarise(dplyr::across(dplyr::any_of("species_synonyms"), ~GROUP_CONCAT(., "|")), .groups = "keep") |> dplyr::ungroup() } @@ -334,10 +334,10 @@ "test_chemical" output_fields$new_field[output_fields$table == "chemicals" & output_fields$field == "ecotox_group"] <- "test_chemical_group" - result <- result %>% + result <- result |> left_join( - tbl(con, "chemicals") %>% - select(union("cas_number", output_fields$field[output_fields$table == "chemicals"])) %>% + tbl(con, "chemicals") |> + select(union("cas_number", output_fields$field[output_fields$table == "chemicals"])) |> dplyr::rename_with( function(x){ c("test_cas", "test_chemical", "test_chemical_group")[match(x, c("cas_number", "chemical_name", "ecotox_group"))] @@ -346,16 +346,16 @@ } if ("references" %in% output_fields$table) { - result <- result %>% + result <- result |> left_join( - tbl(con, "references") %>% + tbl(con, "references") |> select(union("reference_number", output_fields$field[output_fields$table == "references"])), "reference_number" ) } ## join remaining lookup values - result <- result %>% .process_lookups("tests") + result <- result |> .process_lookups("tests") renamed <- output_fields$field != output_fields$new_field message( @@ -369,22 +369,22 @@ ) ) - result <- result %>% select(dplyr::any_of(union(unique(output_fields$new_field), "result_id"))) + result <- result |> select(dplyr::any_of(union(unique(output_fields$new_field), "result_id"))) return(result) } .group_nest_results <- function(search_result) { if (nrow(search_result) > 0) { group_by <- - search_result %>% - dplyr::group_by(dplyr::across(dplyr::any_of("result_id"))) %>% - dplyr::summarise_all(~all(is.na(.)) || all(.[[1]] == .)) %>% - dplyr::ungroup() %>% - select(tidyselect::vars_select_helpers$where(~ all(.))) %>% + search_result |> + dplyr::group_by(dplyr::across(dplyr::any_of("result_id"))) |> + dplyr::summarise_all(~all(is.na(.)) || all(.[[1]] == .)) |> + dplyr::ungroup() |> + select(tidyselect::vars_select_helpers$where(~ all(.))) |> colnames() if (all(colnames(search_result) %in% group_by)) return (search_result) else{ search_result <- - search_result %>% + search_result |> dplyr::group_nest(dplyr::across(dplyr::any_of(group_by)), .key = "nested_data") } } else search_result diff --git a/R/imports.r b/R/imports.r index 0706358..118f8f5 100644 --- a/R/imports.r +++ b/R/imports.r @@ -10,19 +10,6 @@ #' @importFrom dplyr collect left_join inner_join select sql tbl #' @importFrom lifecycle badge -#' @importFrom rlang := +#' @importFrom rlang := !!! #' @importFrom RSQLite dbExecute dbConnect dbDisconnect dbWriteTable NULL - -#' Objects exported from other packages -#' -#' Objects imported and exported from other packages. See original documentation for more details. -#' -#' \describe{ -#' \item{dplyr}{[`\%>\%()`][dplyr::reexports]} -#' } -#' @importFrom dplyr %>% -#' @export %>% -#' @name %>% -#' @rdname reexports -NULL diff --git a/R/init.r b/R/init.r index 909e649..9c42281 100644 --- a/R/init.r +++ b/R/init.r @@ -10,7 +10,7 @@ #' @param verify_ssl When set to `FALSE` the SSL certificate of the host (EPA) #' is not verified. Can also be set as option: #' `options(ECOTOXr_verify_ssl = TRUE)`. Default is `TRUE`. -#' @param ... arguments passed on to [httr::GET()] +#' @param ... arguments passed on to [httr2::req_options()] #' @returns Returns a `character` string containing the download URL of the latest version of the EPA ECOTOX #' database. #' @rdname get_ecotox_url @@ -24,8 +24,10 @@ get_ecotox_url <- function(verify_ssl = getOption("ECOTOXr_verify_ssl"), ...) { if (is.null(verify_ssl)) verify_ssl <- TRUE args <- list(...) - if (!verify_ssl) - args[["config"]] <- httr::config(ssl_verifyhost = 0, ssl_verifypeer = 0) + if (!verify_ssl) { + args[["ssl_verifyhost"]] <- 0 + args[["ssl_verifypeer"]] <- 0 + } link <- tryCatch({ do.call(.get_ecotox_url, c(url = "https://cfpub.epa.gov/ecotox/index.cfm", args)) @@ -37,16 +39,18 @@ get_ecotox_url <- function(verify_ssl = getOption("ECOTOXr_verify_ssl"), ...) { } .get_ecotox_url <- function(url, ...) { - link <- - httr::GET(url, ...) %>% - rvest::read_html() %>% - rvest::html_elements("a") %>% + link <- + httr2::request(url) |> + httr2::req_options(...) |> + httr2::req_perform() |> + httr2::resp_body_html() |> + rvest::html_elements("a") |> rvest::html_attr("href") link <- link[!is.na(link) & endsWith(link, ".zip")] if (length(link) == 0) stop("Could not find ASCII download link...") link[!startsWith(link, "http")] <- paste0(url, link[!startsWith(link, "http")]) link_dates <- - stringr::str_sub(link, -14, -5) %>% + stringr::str_sub(link, -14, -5) |> as.Date(format = "%m_%d_%Y") link[which(link_dates == max(link_dates))] } @@ -69,8 +73,7 @@ get_ecotox_url <- function(verify_ssl = getOption("ECOTOXr_verify_ssl"), ...) { #' @export check_ecotox_availability <- function(target = get_ecotox_path()) { files <- list.files(target) - file_reg <- gregexpr("(?<=^ecotox_ascii_)(.*?)(?=\\.sqlite$)", files, perl = T) - file_reg <- regmatches(files, file_reg) + file_reg <- stringr::str_extract(files, "(?<=^ecotox_ascii_)(.*?)(?=\\.sqlite$)") files <- files[unlist(lapply(file_reg, length)) > 0] file_reg <- unlist(file_reg[unlist(lapply(file_reg, length)) > 0]) @@ -149,7 +152,7 @@ get_ecotox_path <- function() { #' the user is asked on the command line what to do in those cases. Set this parameter to `FALSE` in order #' to continue without warning and asking. #' @inheritParams get_ecotox_url -#' @param ... Arguments passed on to [httr::GET()]. +#' @param ... Arguments passed on to [httr2::req_options()]. #' @returns Returns `NULL` invisibly. #' @rdname download_ecotox_data #' @name download_ecotox_data @@ -187,23 +190,18 @@ download_ecotox_data <- function( } if (proceed.download) { message(crayon::white(sprintf("Start downloading ECOTOX data from %s...\n", link))) - cfg <- list( - noprogress = 0L, - progressfunction = function(down, up) { - message(crayon::white(sprintf("\r%0.1f MB downloaded...", - down[2]/(1024*1024))), appendLF = FALSE) - TRUE - }) + cfg <- list(...) if (!verify_ssl) { cfg[["ssl_verifyhost"]] <- 0 cfg[["ssl_verifypeer"]] <- 0 - } - cfg <- do.call(httr::config, cfg) - - httr::GET(link, config = cfg, - httr::write_disk(dest_path, overwrite = TRUE), ...) + } - message(crayon::green(" Done\n")) + httr2::request(link) |> + httr2::req_options(!!!cfg) |> + httr2::req_progress() |> + httr2::req_perform(path = dest_path) + + message(crayon::green("Done\n")) } ## create bib-file for later reference diff --git a/R/online.r b/R/online.r index 235fbff..78d1fa5 100644 --- a/R/online.r +++ b/R/online.r @@ -18,7 +18,7 @@ #' @inheritParams get_ecotox_url #' @param ... In case of [list_ecotox_web_fields()] the dots can be used as search field values used to update the returned list of fields. #' -#' In case of [websearch_ecotox()] the dots can be used to pass custom options to the underlying [httr::POST()] call. For available +#' In case of [websearch_ecotox()] the dots can be used to pass custom options to the underlying [httr2::req_options()] call. For available #' field names, use `names(list_ecotox_web_fields())` #' @returns Returns named `list` of [dplyr::tibble]s with search results. Results are unpolished and `as is' returned by EPA's web service. #' @@ -45,41 +45,43 @@ websearch_ecotox <- function( verify_ssl = getOption("ECOTOXr_verify_ssl"), ...) { habitat <- match.arg(habitat) if (is.null(verify_ssl)) verify_ssl <- TRUE - - search_post <- list( - url = sprintf("https://cfpub.epa.gov/ecotox/data/search_handler.cfm?sub=%s&type=", habitat), - body = fields, encode = "form", - ... - ) + cfg = list(...) if (!verify_ssl) { - search_post[["config"]] <- httr::config(ssl_verifyhost = 0, ssl_verifypeer = 0) + cfg[["ssl_verifyhost"]] <- 0 + cfg[["ssl_verifypeer"]] <- 0 } ## download preview - search_post <- do.call(httr::POST, search_post) + search_post <- + sprintf("https://cfpub.epa.gov/ecotox/data/search_handler.cfm?sub=%s&type=", habitat) |> + httr2::request() |> + httr2::req_method("POST") |> + httr2::req_body_form(!!!fields) |> + httr2::req_options(!!!cfg) |> + httr2::req_perform() .check_http_status(search_post, "Failed to send search query") - search_response <- rvest::read_html(search_post) - warnings <- search_response %>% rvest::html_element(xpath = "//div[@class='callout alert']") %>% rvest::html_text2() + search_response <- search_post |> httr2::resp_body_html() + warnings <- search_response |> rvest::html_element(xpath = "//div[@class='callout alert']") |> + rvest::html_text2() if (!is.na(warnings)) stop(warnings) - search_response <- jsonlite::parse_json(search_post$content %>% rawToChar()) - headers <- lapply(search_response$headers, `[[`, 1) %>% unlist() - table_preview <- search_response$records %>% lapply(structure, names = headers) %>% lapply(dplyr::as_tibble) %>% dplyr::bind_rows() + search_response <- jsonlite::parse_json(search_post |> httr2::resp_body_string()) + headers <- lapply(search_response$headers, `[[`, 1) |> unlist() + table_preview <- search_response$records |> lapply(structure, names = headers) |> lapply(dplyr::as_tibble) |> dplyr::bind_rows() - httr_result <- list( - url = sprintf("https://cfpub.epa.gov/ecotox/data/search_handler.cfm?sub=%s&type=excel", habitat), - body = fields, encode = "form", - ... - ) - if (!verify_ssl) { - httr_result[["config"]] <- httr::config(ssl_verifyhost = 0, ssl_verifypeer = 0) - } ## Download excel report - httr_result <- do.call(httr::POST, httr_result) - + httr_result <- + sprintf("https://cfpub.epa.gov/ecotox/data/search_handler.cfm?sub=%s&type=excel", habitat) |> + httr2::request() |> + httr2::req_method("POST") |> + httr2::req_body_form(!!!fields) |> + httr2::req_options(!!!cfg) |> + httr2::req_perform() + .check_http_status(httr_result, "Failed to send search query") ## Return preview when Excel download has failed if (!grepl("spreadsheet", httr_result$headers$`content-type`)) { - warn_text <- httr_result %>% rvest::read_html() %>% rvest::html_text2() %>% stringr::str_replace("Warning", "") %>% trimws() + warn_text <- httr_result |> httr2::resp_body_html() |> rvest::html_text2() |> + stringr::str_replace("Warning", "") |> trimws() warn_text <- paste(warn_text, "Returning on-line preview data only") warning(warn_text) return(list(`On-line preview` = table_preview)) @@ -87,7 +89,7 @@ websearch_ecotox <- function( ## otherwise return full data tab_file <- tempfile(fileext = ".xlsx") - writeBin(httr_result$content, tab_file) + writeBin(httr_result$body, tab_file) sheet_names <- readxl::excel_sheets(tab_file) data_tables <- suppressMessages( @@ -116,7 +118,7 @@ list_ecotox_web_fields <- function(...) { form_data <- do.call(c, lapply(form_data, function(x) { x <- strsplit(x[[1]], "=")[[1]] structure(ifelse(is.na(x[2]), "", gsub("[+]", " ", utils::URLdecode(x[2]))), names = x[1]) - })) %>% as.list() + })) |> as.list() form_data$Ending_Publication_Year <- format(Sys.Date(), "%Y") form_data[names(c(...))] <- c(...) return(form_data) @@ -145,7 +147,7 @@ list_ecotox_web_fields <- function(...) { #' @inheritParams get_ecotox_url #' @returns Returns a named `list` of [dplyr::tibble]s containing the search results for the requested output tables and fields. #' Results are unpolished and `as is' returned by EPA's web service. -#' @param ... Arguments passed on to [httr::GET] requests. +#' @param ... Arguments passed on to [httr2::req_options()] requests. #' @rdname websearch_comptox #' @name websearch_comptox #' @examples @@ -198,6 +200,11 @@ websearch_comptox <- function( verify_ssl = getOption("ECOTOXr_verify_ssl"), ...) { if (is.null(verify_ssl)) verify_ssl <- TRUE + cfg <- list(...) + if (!verify_ssl) { + cfg[["ssl_verifyhost"]] <- 0 + cfg[["ssl_verifypeer"]] <- 0 + } search_form <- list( identifierTypes = match.arg(identifierTypes, several.ok = T), @@ -207,48 +214,43 @@ websearch_comptox <- function( inputType = match.arg(inputType), downloadType = "EXCEL" ) - post_result <- list( - url = "https://comptox.epa.gov/dashboard-api/batchsearch/export/?lb2ljny4", - body = search_form, - encode = "json", - httr::content_type("application/json"), - ...) - if (!verify_ssl) { - post_result[["config"]] <- httr::config(ssl_verifyhost = 0, ssl_verifypeer = 0) - } - post_result <- do.call(httr::POST, post_result) + + post_result <- + "https://comptox.epa.gov/dashboard-api/batchsearch/export/?lb2ljny4" |> + httr2::request() |> + httr2::req_body_json(search_form) |> + httr2::req_method("POST") |> + httr2::req_options(!!!cfg) |> + httr2::req_perform() .check_http_status(post_result, "Failed to post search query") ## Wait for download to get ready, by checking its status every second i <- 0 repeat { - search_status <- list( - url = paste0("https://comptox.epa.gov/dashboard-api/batchsearch/export/status/", post_result$content %>% rawToChar()), - ... - ) - if (!verify_ssl) - search_status[["config"]] <- httr::config(ssl_verifyhost = 0, ssl_verifypeer = 0) - search_status <- do.call(httr::GET, search_status) + search_status <- + "https://comptox.epa.gov/dashboard-api/batchsearch/export/status/" |> + paste0(post_result |> httr2::resp_body_string()) |> + httr2::request() |> + httr2::req_options(!!!cfg) |> + httr2::req_perform() .check_http_status(search_status, "Failed to check download status") - if ((search_status$content %>% rawToChar()) == "true") break + if ((search_status |> httr2::resp_body_string()) == "true") break i <- i + 1 if (i == 30) warning("It is taking exceptionally long for preparing the download, you may wish to abort...") if (i == timeout) stop("Did not succeed before timeout, try again or increase the timeout...") Sys.sleep(1) } - search_result <- list( - url = paste0("https://comptox.epa.gov/dashboard-api/batchsearch/export/content/", post_result$content %>% rawToChar()), - httr::content_type("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"), - ... - ) - if (!verify_ssl) - search_result[["config"]] <- httr::config(ssl_verifyhost = 0, ssl_verifypeer = 0) ## Download is ready, so let's go get it - search_result <- do.call(httr::GET, search_result) + search_result <- + "https://comptox.epa.gov/dashboard-api/batchsearch/export/content/" |> + paste0(post_result |> httr2::resp_body_string()) |> + httr2::request() |> + httr2::req_options(!!!cfg) |> + httr2::req_perform() .check_http_status(search_result, "Failed to obtain search result") tab_file <- tempfile(fileext = ".xlsx") - writeBin(search_result$content, tab_file) + writeBin(search_result$body, tab_file) sheet_names <- readxl::excel_sheets(tab_file) data_tables <- structure( lapply(sheet_names, function(name) { @@ -260,13 +262,12 @@ websearch_comptox <- function( return(data_tables) } -.check_http_status <- function(httr_object, message = "") { +.check_http_status <- function(httr2_response, message = "") { ## http status between 200 and 299 indicates success - if (!dplyr::between(as.numeric(httr_object$status), 200, 299)) { - stop(sprintf("%s. Http response %s status code %s\n\n%s", + if (!dplyr::between(as.numeric(httr2_response$status_code), 200, 299)) { + stop(sprintf("%s. Http response %s status code %s", message, - httr::content(httr_object)$title, - httr::content(httr_object)$status, - httr::content(httr_object)$detail)) + httr2::resp_status_desc(httr2_response), + httr2::resp_status(httr2_response))) } } \ No newline at end of file diff --git a/R/wrappers.r b/R/wrappers.r index cc11d0d..55bd0e4 100644 --- a/R/wrappers.r +++ b/R/wrappers.r @@ -117,7 +117,7 @@ search_ecotox <- function(search, output_fields = list_ecotox_fields("default"), search_result <- search_ecotox_lazy(search, c(output_fields, temp_field), compute, group_by_results = group_by_results) database_file <- attributes(search_result)$database_file dbcon <- search_result[["src"]]$con - search_result <- search_result %>% collect() + search_result <- search_result |> collect() dbDisconnect(dbcon) ## group by result_id if requested @@ -126,9 +126,9 @@ search_ecotox <- function(search, output_fields = list_ecotox_fields("default"), ## remove temporary fields if (!is.null(temp_field)) search_result <- - search_result %>% + search_result |> select(!dplyr::any_of(gsub("^.*?[.]", "", temp_field))) - if (as_data_frame) search_result <- search_result %>% as.data.frame() + if (as_data_frame) search_result <- search_result |> as.data.frame() return(.add_tags(search_result, database_file)) } @@ -155,6 +155,6 @@ search_ecotox_lazy <- function(search, output_fields = list_ecotox_fields("defau search_query_ecotox <- function(search, output_fields = list_ecotox_fields("default"), ...) { search_result <- search_ecotox_lazy(search, output_fields, ...) database_file <- attributes(search_result)$database_file - search_result <- search_result %>% dbplyr::sql_render() + search_result <- search_result |> dbplyr::sql_render() return(.add_tags(search_result, database_file)) } diff --git a/README.Rmd b/README.Rmd index ab5bee5..e8ed78f 100644 --- a/README.Rmd +++ b/README.Rmd @@ -103,8 +103,8 @@ If you like to use [`{dplyr}`](https://dplyr.tidyverse.org/) verbs, you are in l ```{r warning = FALSE} con <- dbConnectEcotox() -dplyr::tbl(con, "results") %>% - dplyr::filter(result_id == "401386") %>% +dplyr::tbl(con, "results") |> + dplyr::filter(result_id == "401386") |> dplyr::collect() ``` @@ -115,7 +115,7 @@ needs knowledge of the database structure in order to join additional data. > Using `SQL` syntax ```{r warning = FALSE} -dbGetQuery(con, "SELECT * FROM results WHERE result_id='401386'") %>% +dbGetQuery(con, "SELECT * FROM results WHERE result_id='401386'") |> dplyr::as_tibble() ``` diff --git a/README.md b/README.md index bc311f4..4669f65 100644 --- a/README.md +++ b/README.md @@ -12,12 +12,12 @@ ECOTOX database](https://cfpub.epa.gov/ecotox/). More specifically you can: -- Build a local SQLite copy of the [US EPA ECOTOX - database](https://cfpub.epa.gov/ecotox/) -- Search and extract data from the local database -- Use experimental features to search the on-line dashboards: - [ECOTOX](https://cfpub.epa.gov/ecotox/search.cfm) and - [CompTox](https://comptox.epa.gov/dashboard/batch-search) +- Build a local SQLite copy of the [US EPA ECOTOX + database](https://cfpub.epa.gov/ecotox/) +- Search and extract data from the local database +- Use experimental features to search the on-line dashboards: + [ECOTOX](https://cfpub.epa.gov/ecotox/search.cfm) and + [CompTox](https://comptox.epa.gov/dashboard/batch-search) ## Why use `{ECOTOXr}`? @@ -97,17 +97,17 @@ search_ecotox( #> 'chemicals.cas_number' was renamed 'test_cas' #> 'chemicals.chemical_name' was renamed 'test_chemical' #> 'dose_responses.dose_resp_id' was renamed 'dose_link_dose_resp_id' -#> # A tibble: 1 x 98 -#> test_cas test_grade test_gra~1 test_~2 test_~3 test_~4 test_~5 test_~6 test_~7 -#> * -#> 1 71432 NR "" "" NR NR NR -#> # ... with 89 more variables: test_purity_comments , -#> # organism_lifestage , organism_age_mean_op , -#> # organism_age_mean , organism_age_min_op , organism_age_min , +#> # A tibble: 1 × 98 +#> test_cas test_grade test_grade_comments test_purity_mean_op test_purity_mean +#> * +#> 1 71432 NR "" "" NR +#> # ℹ 93 more variables: test_purity_min_op , test_purity_min , +#> # test_purity_max_op , test_purity_max , +#> # test_purity_comments , organism_lifestage , +#> # organism_age_mean_op , organism_age_mean , +#> # organism_age_min_op , organism_age_min , #> # organism_age_max_op , organism_age_max , -#> # exposure_duration_mean_op , exposure_duration_mean , -#> # exposure_duration_min_op , exposure_duration_min , -#> # exposure_duration_max_op , exposure_duration_max , ... +#> # exposure_duration_mean_op , exposure_duration_mean , … ``` If you like to use [`{dplyr}`](https://dplyr.tidyverse.org/) verbs, you @@ -121,20 +121,20 @@ structure. ``` r con <- dbConnectEcotox() -dplyr::tbl(con, "results") %>% - dplyr::filter(result_id == "401386") %>% +dplyr::tbl(con, "results") |> + dplyr::filter(result_id == "401386") |> dplyr::collect() -#> # A tibble: 1 x 137 -#> result_id test_id sample_siz~1 sampl~2 sampl~3 sampl~4 sampl~5 sampl~6 sampl~7 -#> -#> 1 401386 1020021 "" NC "" NC "" NC NC -#> # ... with 128 more variables: sample_size_comments , +#> # A tibble: 1 × 137 +#> result_id test_id sample_size_mean_op sample_size_mean sample_size_min_op +#> +#> 1 401386 1020021 "" NC "" +#> # ℹ 132 more variables: sample_size_min , sample_size_max_op , +#> # sample_size_max , sample_size_unit , sample_size_comments , #> # obs_duration_mean_op , obs_duration_mean , #> # obs_duration_min_op , obs_duration_min , #> # obs_duration_max_op , obs_duration_max , obs_duration_unit , #> # obs_duration_comments , endpoint , endpoint_comments , -#> # trend , effect , effect_comments , measurement , -#> # measurement_comments , response_site , ... +#> # trend , effect , effect_comments , measurement , … ``` If you prefer working using `SQL` directly, that is fine too. The @@ -146,19 +146,19 @@ the database structure in order to join additional data. > Using `SQL` syntax ``` r -dbGetQuery(con, "SELECT * FROM results WHERE result_id='401386'") %>% +dbGetQuery(con, "SELECT * FROM results WHERE result_id='401386'") |> dplyr::as_tibble() -#> # A tibble: 1 x 137 -#> result_id test_id sample_siz~1 sampl~2 sampl~3 sampl~4 sampl~5 sampl~6 sampl~7 -#> -#> 1 401386 1020021 "" NC "" NC "" NC NC -#> # ... with 128 more variables: sample_size_comments , +#> # A tibble: 1 × 137 +#> result_id test_id sample_size_mean_op sample_size_mean sample_size_min_op +#> +#> 1 401386 1020021 "" NC "" +#> # ℹ 132 more variables: sample_size_min , sample_size_max_op , +#> # sample_size_max , sample_size_unit , sample_size_comments , #> # obs_duration_mean_op , obs_duration_mean , #> # obs_duration_min_op , obs_duration_min , #> # obs_duration_max_op , obs_duration_max , obs_duration_unit , #> # obs_duration_comments , endpoint , endpoint_comments , -#> # trend , effect , effect_comments , measurement , -#> # measurement_comments , response_site , ... +#> # trend , effect , effect_comments , measurement , … ``` ## Disclaimers @@ -173,13 +173,13 @@ package is therefore **not** official US EPA software. ## Resources -- [Manual of the CRAN - release](https://CRAN.R-project.org/package=ECOTOXr) -- EPA ECOTOX help -- Olker, Jennifer H.; Elonen, Colleen M.; Pilli, Anne; Anderson, Arne; - Kinziger, Brian; Erickson, Stephen; Skopinski, Michael; Pomplun, - Anita; LaLone, Carlie A.; Russom, Christine L.; Hoff, Dale. (2022): - The ECOTOXicology Knowledgebase: A Curated Database of Ecologically - Relevant Toxicity Tests to Support Environmental Research and Risk - Assessment. *Environmental Toxicology and Chemistry* 41(6) 1520-1539 - +- [Manual of the CRAN + release](https://CRAN.R-project.org/package=ECOTOXr) +- EPA ECOTOX help +- Olker, Jennifer H.; Elonen, Colleen M.; Pilli, Anne; Anderson, Arne; + Kinziger, Brian; Erickson, Stephen; Skopinski, Michael; Pomplun, + Anita; LaLone, Carlie A.; Russom, Christine L.; Hoff, Dale. (2022): + The ECOTOXicology Knowledgebase: A Curated Database of Ecologically + Relevant Toxicity Tests to Support Environmental Research and Risk + Assessment. *Environmental Toxicology and Chemistry* 41(6) 1520-1539 + diff --git a/man/check_ecotox_build.Rd b/man/check_ecotox_build.Rd new file mode 100644 index 0000000..b32167d --- /dev/null +++ b/man/check_ecotox_build.Rd @@ -0,0 +1,48 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/database_access.r +\name{check_ecotox_build} +\alias{check_ecotox_build} +\title{Check the locally build database for validity} +\usage{ +check_ecotox_build(path = get_ecotox_path(), version, ...) +} +\arguments{ +\item{path}{A \code{character} string with the path to the location of the local database (default is +\code{\link[=get_ecotox_path]{get_ecotox_path()}}).} + +\item{version}{A \code{character} string referring to the release version of the database you wish to locate. +It should have the same format as the date in the EPA download link, which is month, day, year, separated by +underscores ("\%m_\%d_\%Y"). When missing, the most recent available copy is selected automatically.} + +\item{...}{Arguments that are passed to \code{\link[RSQLite:SQLite]{dbConnect()}} method +or \code{\link[RSQLite:SQLite]{dbDisconnect()}} method.} +} +\value{ +Returns an indicative logical value whether the database is not corrupted. +\code{TRUE} indicates the database is most likely OK. \code{FALSE} indicates that something might +be wrong. Additional messages (when \code{FALSE}) are included as attributes containing hints +on the outcoming of the tests. See also the 'details' section. +} +\description{ +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} Performs some simple tests to check whether the +locally built database is not corrupted. +} +\details{ +For now this function tests if all expected tables are present in the locally built +database. Note that in later release of the database some tables were added. Therefore +for older builds this function might return \code{FALSE} whereas it is actually just fine +(just out-dated). + +Furthermore, this function tests if all tables contain one or more records. Obviously, +this is no guarantee that the database is valid, but it is a start. + +More tests may be added in future releases. +} +\examples{ +\dontrun{ +check_ecotox_build() +} +} +\author{ +Pepijn de Vries +} diff --git a/man/check_ecotox_version.Rd b/man/check_ecotox_version.Rd new file mode 100644 index 0000000..fd3111e --- /dev/null +++ b/man/check_ecotox_version.Rd @@ -0,0 +1,36 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/database_access.r +\name{check_ecotox_version} +\alias{check_ecotox_version} +\title{Check if the locally build database is up to date} +\usage{ +check_ecotox_version(path = get_ecotox_path(), version, verbose = TRUE) +} +\arguments{ +\item{path}{When you have a copy of the database somewhere other than the default +directory (\code{\link[=get_ecotox_path]{get_ecotox_path()}}), you can provide the path here.} + +\item{version}{A \code{character} string referring to the release version of the database you wish to locate. +It should have the same format as the date in the EPA download link, which is month, day, year, separated by +underscores ("\%m_\%d_\%Y"). When missing, the most recent available copy is selected automatically.} + +\item{verbose}{A \code{logical} value. If true messages are shown on the console reporting +on the check.} +} +\value{ +Returns a \code{logical} value invisibly indicating whether the locally build +is up to date with the latest release by the EPA. +} +\description{ +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} Checks the version of the database available on-line +from the EPA against the specified version (latest by default) of the database build +locally. Returns \code{TRUE} when they are the same. +} +\examples{ +\dontrun{ +check_ecotox_version() +} +} +\author{ +Pepijn de Vries +} diff --git a/man/download_ecotox_data.Rd b/man/download_ecotox_data.Rd index 5ed0756..4957621 100644 --- a/man/download_ecotox_data.Rd +++ b/man/download_ecotox_data.Rd @@ -27,7 +27,7 @@ to continue without warning and asking.} is not verified. Can also be set as option: \code{options(ECOTOXr_verify_ssl = TRUE)}. Default is \code{TRUE}.} -\item{...}{Arguments passed on to \code{\link[httr:GET]{httr::GET()}}.} +\item{...}{Arguments passed on to \code{\link[httr2:req_options]{httr2::req_options()}}.} } \value{ Returns \code{NULL} invisibly. diff --git a/man/get_ecotox_url.Rd b/man/get_ecotox_url.Rd index bde7338..7cbb8f4 100644 --- a/man/get_ecotox_url.Rd +++ b/man/get_ecotox_url.Rd @@ -11,7 +11,7 @@ get_ecotox_url(verify_ssl = getOption("ECOTOXr_verify_ssl"), ...) is not verified. Can also be set as option: \code{options(ECOTOXr_verify_ssl = TRUE)}. Default is \code{TRUE}.} -\item{...}{arguments passed on to \code{\link[httr:GET]{httr::GET()}}} +\item{...}{arguments passed on to \code{\link[httr2:req_options]{httr2::req_options()}}} } \value{ Returns a \code{character} string containing the download URL of the latest version of the EPA ECOTOX diff --git a/man/reexports.Rd b/man/reexports.Rd deleted file mode 100644 index 52f9b9d..0000000 --- a/man/reexports.Rd +++ /dev/null @@ -1,13 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/imports.r -\name{\%>\%} -\alias{\%>\%} -\title{Objects exported from other packages} -\description{ -Objects imported and exported from other packages. See original documentation for more details. -} -\details{ -\describe{ -\item{dplyr}{\code{\link[dplyr:reexports]{\\\%>\\\%()}}} -} -} diff --git a/man/websearch.Rd b/man/websearch.Rd index 68ca09a..191a982 100644 --- a/man/websearch.Rd +++ b/man/websearch.Rd @@ -27,7 +27,7 @@ is not verified. Can also be set as option: \item{...}{In case of \code{\link[=list_ecotox_web_fields]{list_ecotox_web_fields()}} the dots can be used as search field values used to update the returned list of fields. -In case of \code{\link[=websearch_ecotox]{websearch_ecotox()}} the dots can be used to pass custom options to the underlying \code{\link[httr:POST]{httr::POST()}} call. For available +In case of \code{\link[=websearch_ecotox]{websearch_ecotox()}} the dots can be used to pass custom options to the underlying \code{\link[httr2:req_options]{httr2::req_options()}} call. For available field names, use \code{names(list_ecotox_web_fields())}} } \value{ diff --git a/man/websearch_comptox.Rd b/man/websearch_comptox.Rd index 48d1990..cc59684 100644 --- a/man/websearch_comptox.Rd +++ b/man/websearch_comptox.Rd @@ -64,7 +64,7 @@ It will throw an error if it takes longer than the specified \code{timeout}.} is not verified. Can also be set as option: \code{options(ECOTOXr_verify_ssl = TRUE)}. Default is \code{TRUE}.} -\item{...}{Arguments passed on to \link[httr:GET]{httr::GET} requests.} +\item{...}{Arguments passed on to \code{\link[httr2:req_options]{httr2::req_options()}} requests.} } \value{ Returns a named \code{list} of \link[dplyr:reexports]{dplyr::tibble}s containing the search results for the requested output tables and fields. diff --git a/tests/testthat/test_that.r b/tests/testthat/test_that.r index cdee0dc..192d118 100644 --- a/tests/testthat/test_that.r +++ b/tests/testthat/test_that.r @@ -299,6 +299,6 @@ test_that("When multiple doses are linked to a result, no duplicates are returne ################################# test_that("get_ecotox_info doesn't throw an error.", { - expect_false({ throws_errors(get_ecotox_info()) }) + expect_false({ throws_errors(suppressMessages(get_ecotox_info())) }) })