From 3d715e2544ea9976891ff6e3ea879cab586cc23e Mon Sep 17 00:00:00 2001 From: banky <41001537+bahadzie@users.noreply.github.com> Date: Wed, 31 Jan 2024 16:45:07 +0000 Subject: [PATCH] Remove \dontrun{} when not strictly required (#61) * add the examples to the functions documentations * build documentation for show_tables() and visualise_table() * Update CITATION.cff * update function's examples * fix linters * add new lines * remove unnecessary nolint * use explicit URL * update show_example_file documentation * align argument in function documentation * Automatic readme update * add examples and remove dontrun{} when not needed in DHIS2 related functions * add examples and remove dontrun{} when not needed in Fingertips related functions * add examples and remove dontrun{} when not needed in REDCap related functions * add examples and remove dontrun{} when not needed in server related functions * add examples and remove dontrun{} when not needed in readepi related functions * run devtools::document() * remove README.html * rearrange arguments in read_from_readcap example * complete test example for dhis2_get_attributes_from_user * Update _pkgdown.yml to account for read_from_fingertips * update on dhis2_get_attributes_from_user() * Update CITATION.cff * remove examples in internal functions documentation - for functions without dontrun{} * Update R/read_from_fingertips.R remove @noRd in the function documentation Co-authored-by: Hugo Gruson <10783929+Bisaloo@users.noreply.github.com> --------- Co-authored-by: Karim-Mane Co-authored-by: GitHub Action Co-authored-by: Karim MANE <84502011+Karim-Mane@users.noreply.github.com> Co-authored-by: Hugo Gruson <10783929+Bisaloo@users.noreply.github.com> --- CITATION.cff | 60 +-- DESCRIPTION | 3 +- R/check_dhis2_attributes-helpers.R | 20 +- R/read_from_dhis2-helpers.R | 16 +- R/read_from_dhis2.R | 1 - R/read_from_fingertips-helpers.R | 15 +- R/read_from_fingertips.R | 2 + R/read_from_redcap-helpers.R | 53 ++- R/read_from_redcap.R | 14 +- R/read_servers.R | 3 +- R/read_servers_helpers.R | 26 +- R/readepi.R | 2 +- R/readepi_helpers.R | 13 +- R/show_example_file.R | 2 + R/show_tables.R | 3 +- README.html | 445 ------------------ README.md | 50 +- _pkgdown.yml | 2 +- man/dhis2_get_relevant_attributes.Rd | 8 +- man/dhis2_login.Rd | 11 +- man/dhis2_make_api_request.Rd | 11 + man/dhis2_subset_fields.Rd | 2 +- man/dhis2_subset_records.Rd | 3 +- man/fingertips_get_args.Rd | 11 +- man/fingertips_get_profile_name.Rd | 14 + man/read_from_fingertips.Rd | 63 --- man/read_from_redcap.Rd | 24 +- man/redcap_import_data.Rd | 17 +- man/redcap_read_data.Rd | 10 + man/redcap_read_fields.Rd | 11 + man/redcap_read_records.Rd | 12 + man/redcap_read_rows_columns.Rd | 13 + man/show_example_file.Rd | 1 + man/show_tables.Rd | 3 +- man/sql_identify_table_name.Rd | 8 - man/sql_server_read_data.Rd | 2 +- man/visualise_table.Rd | 14 +- tests/testthat/test-read_from_dhis2_helpers.R | 18 + tests/testthat/test-read_servers_helpers.R | 24 + 39 files changed, 357 insertions(+), 653 deletions(-) delete mode 100644 README.html delete mode 100644 man/read_from_fingertips.Rd diff --git a/CITATION.cff b/CITATION.cff index 4153ea99..e4359e11 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -55,34 +55,34 @@ references: abstract: 'checkmate: Fast and Versatile Argument Checks' notes: Imports url: https://mllg.github.io/checkmate/ - repository: https://packagemanager.posit.co/cran/latest/ + repository: https://CRAN.R-project.org/package=checkmate authors: - family-names: Lang given-names: Michel email: michellang@gmail.com orcid: https://orcid.org/0000-0001-9754-0393 - year: '2023' + year: '2024' - type: software title: DBI abstract: 'DBI: R Database Interface' notes: Imports url: https://dbi.r-dbi.org - repository: https://packagemanager.posit.co/cran/latest/ + repository: https://CRAN.R-project.org/package=DBI authors: - name: R Special Interest Group on Databases (R-SIG-DB) - family-names: Wickham given-names: Hadley - family-names: Müller given-names: Kirill - email: krlmlr+r@mailbox.org + email: kirill@cynkra.com orcid: https://orcid.org/0000-0002-1416-3412 - year: '2023' + year: '2024' - type: software title: dplyr abstract: 'dplyr: A Grammar of Data Manipulation' notes: Imports url: https://dplyr.tidyverse.org - repository: https://packagemanager.posit.co/cran/latest/ + repository: https://CRAN.R-project.org/package=dplyr authors: - family-names: Wickham given-names: Hadley @@ -100,7 +100,7 @@ references: given-names: Davis email: davis@posit.co orcid: https://orcid.org/0000-0003-4777-038X - year: '2023' + year: '2024' - type: software title: fingertipsR abstract: 'fingertipsR: Fingertips Data for Public Health' @@ -115,40 +115,40 @@ references: email: sebsfox@gmail.com - family-names: Flowers given-names: Julian - year: '2023' + year: '2024' version: '>= 1.0.10.9001' - type: software title: glue abstract: 'glue: Interpreted String Literals' notes: Imports url: https://glue.tidyverse.org/ - repository: https://packagemanager.posit.co/cran/latest/ + repository: https://CRAN.R-project.org/package=glue authors: - family-names: Hester given-names: Jim orcid: https://orcid.org/0000-0002-2739-7082 - family-names: Bryan given-names: Jennifer - email: jenny@rstudio.com + email: jenny@posit.co orcid: https://orcid.org/0000-0002-6983-2759 - year: '2023' + year: '2024' - type: software title: httr abstract: 'httr: Tools for Working with URLs and HTTP' notes: Imports url: https://httr.r-lib.org/ - repository: https://packagemanager.posit.co/cran/latest/ + repository: https://CRAN.R-project.org/package=httr authors: - family-names: Wickham given-names: Hadley email: hadley@posit.co - year: '2023' + year: '2024' - type: software title: magrittr abstract: 'magrittr: A Forward-Pipe Operator for R' notes: Imports url: https://magrittr.tidyverse.org - repository: https://packagemanager.posit.co/cran/latest/ + repository: https://CRAN.R-project.org/package=magrittr authors: - family-names: Bache given-names: Stefan Milton @@ -156,28 +156,28 @@ references: - family-names: Wickham given-names: Hadley email: hadley@rstudio.com - year: '2023' + year: '2024' - type: software title: odbc abstract: 'odbc: Connect to ODBC Compatible Databases (using the DBI Interface)' notes: Imports - url: https://r-dbi.github.io/odbc/ - repository: https://packagemanager.posit.co/cran/latest/ + url: https://odbc.r-dbi.org + repository: https://CRAN.R-project.org/package=odbc authors: - family-names: Hester given-names: Jim - family-names: Wickham given-names: Hadley - email: hadley@rstudio.com + email: hadley@posit.co - family-names: Gjoneski given-names: Oliver - year: '2023' + year: '2024' - type: software title: pool abstract: 'pool: Object Pooling' notes: Imports url: http://rstudio.github.io/pool/ - repository: https://packagemanager.posit.co/cran/latest/ + repository: https://CRAN.R-project.org/package=pool authors: - family-names: Cheng given-names: Joe @@ -187,25 +187,25 @@ references: - family-names: Wickham given-names: Hadley email: hadley@posit.co - year: '2023' + year: '2024' - type: software title: REDCapR abstract: 'REDCapR: Interaction Between R and REDCap' notes: Imports url: https://ouhscbbmc.github.io/REDCapR/ - repository: https://packagemanager.posit.co/cran/latest/ + repository: https://CRAN.R-project.org/package=REDCapR authors: - family-names: Beasley given-names: Will email: wibeasley@hotmail.com orcid: https://orcid.org/0000-0002-5613-5006 - year: '2023' + year: '2024' - type: software title: RMySQL abstract: 'RMySQL: Database Interface and ''MySQL'' Driver for R' notes: Imports url: https://downloads.mariadb.org/connector-c/ - repository: https://packagemanager.posit.co/cran/latest/ + repository: https://CRAN.R-project.org/package=RMySQL authors: - family-names: Ooms given-names: Jeroen @@ -220,19 +220,19 @@ references: email: hadley@rstudio.com - family-names: Horner given-names: Jeffrey - year: '2023' + year: '2024' - type: software title: httptest abstract: 'httptest: A Test Environment for HTTP Requests' notes: Suggests url: https://enpiar.com/r/httptest/ - repository: https://packagemanager.posit.co/cran/latest/ + repository: https://CRAN.R-project.org/package=httptest authors: - family-names: Richardson given-names: Neal email: neal.p.richardson@gmail.com orcid: https://orcid.org/0009-0002-7992-3520 - year: '2023' + year: '2024' - type: software title: knitr abstract: 'knitr: A General-Purpose Package for Dynamic Report Generation in R' @@ -244,7 +244,7 @@ references: given-names: Yihui email: xie@yihui.name orcid: https://orcid.org/0000-0003-0645-5666 - year: '2023' + year: '2024' - type: software title: rmarkdown abstract: 'rmarkdown: Dynamic Documents for R' @@ -287,7 +287,7 @@ references: given-names: Richard email: rich@posit.co orcid: https://orcid.org/0000-0003-3925-190X - year: '2023' + year: '2024' - type: software title: testthat abstract: 'testthat: Unit Testing for R' @@ -298,7 +298,7 @@ references: - family-names: Wickham given-names: Hadley email: hadley@posit.co - year: '2023' + year: '2024' version: '>= 3.0.0' identifiers: - type: url diff --git a/DESCRIPTION b/DESCRIPTION index 37379a9d..d370989d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -46,6 +46,7 @@ Remotes: rOpenSci/fingertipsR Config/Needs/website: epiverse-trace/epiversetheme Config/testthat/edition: 3 +SystemRequirements: odbc, libmariadbclient-dev Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 diff --git a/R/check_dhis2_attributes-helpers.R b/R/check_dhis2_attributes-helpers.R index 20aadd3c..79519b7b 100644 --- a/R/check_dhis2_attributes-helpers.R +++ b/R/check_dhis2_attributes-helpers.R @@ -15,7 +15,16 @@ #' @return an object of class `data.frame` that contains the information of #' interest. #' @keywords internal - +#' @examples +#' \dontrun{ +#' response <- dhis2_make_api_request( +#' base_url = file.path("https:/", "play.dhis2.org", "dev"), +#' user_name = "admin", +#' password = "district", +#' which = "dataElements" +#' ) +#' } +#' dhis2_make_api_request <- function(base_url, user_name, password, @@ -59,15 +68,14 @@ dhis2_make_api_request <- function(base_url, #' @examples #' \dontrun{ #' result <- dhis2_get_relevant_attributes( -#' base_url = "https://play.dhis2.org/dev/", -#' user_name = "admin", -#' password = "district", +#' base_url = "https://play.dhis2.org/dev/", +#' user_name = "admin", +#' password = "district", #' attribute_id = "pBOMPrpg1QX,BfMAe6Itzgt", -#' which = "dataSets" +#' which = "dataSets" #' ) #' } #' @keywords internal - dhis2_get_relevant_attributes <- function(base_url, user_name, password, diff --git a/R/read_from_dhis2-helpers.R b/R/read_from_dhis2-helpers.R index abca22f1..3bdb5f69 100644 --- a/R/read_from_dhis2-helpers.R +++ b/R/read_from_dhis2-helpers.R @@ -11,10 +11,17 @@ #' @return a message if the dhis2_login was successful, #' throws an error otherwise. #' -#' @return a message if the login was successfull, thows an error otherwise. +#' @return a message if the login was successful, throws an error otherwise. #' #' @keywords internal -#' +#' @examples +#' \dontrun{ +#' dhis2_login( +#' base_url = file.path("https:/", "play.dhis2.org", "dev"), +#' user_name = "admin", +#' password = "district" +#' ) +#' } dhis2_login <- function(base_url, user_name, password) { @@ -43,7 +50,7 @@ dhis2_login <- function(base_url, #' results <- dhis2_subset_fields( #' data = readepi( #' credentials_file = system.file("extdata", "test.ini", -#' package = "readepi"), +#' package = "readepi"), #' data_source = "https://play.dhis2.org/dev", #' dataset = "pBOMPrpg1QX,BfMAe6Itzgt", #' organisation_unit = "DiszpKrYNg8", @@ -99,8 +106,7 @@ dhis2_subset_fields <- function(data, #' result <- dhis2_subset_records( #' data = readepi( #' credentials_file = system.file("extdata", "test.ini", -#' package = "readepi" -#' ), +#' package = "readepi"), #' data_source = "https://play.dhis2.org/dev", #' dataset = "pBOMPrpg1QX", #' organisation_unit = "DiszpKrYNg8", diff --git a/R/read_from_dhis2.R b/R/read_from_dhis2.R index c0641dc9..4a0e51d4 100644 --- a/R/read_from_dhis2.R +++ b/R/read_from_dhis2.R @@ -20,7 +20,6 @@ #' @returns a `list` of 1 element of type `data frame`. #' @keywords internal #' -#' #' @examples #' \dontrun{ #' data <- read_from_dhis2( diff --git a/R/read_from_fingertips-helpers.R b/R/read_from_fingertips-helpers.R index 971d7a6a..265d5b6c 100644 --- a/R/read_from_fingertips-helpers.R +++ b/R/read_from_fingertips-helpers.R @@ -250,6 +250,18 @@ fingertips_get_id_from_dm_name <- function(metadata = #' @return a `list` of 2 elements of type `character` and `numeric`. These are #' the `profile name` and their correspondent indexes. #' @keywords internal +#' @examples +#' \dontrun{ +#' res <- fingertips_get_profile_name( +#' profile_id = 19L, +#' profile_name = "Public Health Outcomes Framework", +#' metadata = list( +#' indicator_profile_domain = fingertipsR::indicators(), +#' indicator_ids_names = fingertipsR::indicators_unique(), +#' area_type = fingertipsR::area_types() +#' ) +#' ) +#' } #' fingertips_get_profile_name <- function(metadata = list(indicator_profile_domain = @@ -282,8 +294,7 @@ fingertips_get_profile_name <- function(metadata = profile_id) } else if (!is.null(profile_name) && is.null(profile_id)) { profile_name <- unlist(strsplit(profile_name, ",", fixed = TRUE)) - idx <- which( - metadata[["indicator_profile_domain"]][["ProfileName"]] == + idx <- which(metadata[["indicator_profile_domain"]][["ProfileName"]] == profile_name) } diff --git a/R/read_from_fingertips.R b/R/read_from_fingertips.R index 2e7fdc34..587bc2e9 100644 --- a/R/read_from_fingertips.R +++ b/R/read_from_fingertips.R @@ -20,6 +20,8 @@ #' @return a `list` of 1 element of type `data.frame`. This contains the #' imported dataset of interest. #' +#' @keywords internal +#' #' @examples #' \dontrun{ #' data <- read_from_fingertips(indicator_id = 90362, area_type_id = 202) diff --git a/R/read_from_redcap-helpers.R b/R/read_from_redcap-helpers.R index c0599d40..e0133fce 100644 --- a/R/read_from_redcap-helpers.R +++ b/R/read_from_redcap-helpers.R @@ -1,4 +1,4 @@ -#' Import data from REDCap under all scenari +#' Import data from REDCap under all scenario #' #' @description This is a wrapper across all the use case of reading data from #' REDCap i.e. around the function that all records and fields from the @@ -17,6 +17,19 @@ #' @return a `list` of 2 elements of type `data.frame`. These are the dataset of #' interest and its associated metadata. #' @keywords internal +#' @examples +#' \dontrun{ +#' result <- redcap_import_data( +#' base_url = file.path("https:/", "bbmc.ouhsc.edu", +#' "redcap", "api", ""), +#' token = "9A81268476645C4E5F03428B8AC3AA7B", +#' records = c("1", "3", "5"), +#' fields = c("record_id", "name_first", "age", "bmi"), +#' id_position = 1L, +#' id_col_name = NULL +#' ) +#' } +#' #' redcap_import_data <- function(base_url, token, @@ -59,6 +72,14 @@ redcap_import_data <- function(base_url, #' @return a `list` of 2 elements of type `data.frame` that contain the project #' data and its associated metadata. #' @keywords internal +#' @examples +#' \dontrun{ +#' result <- redcap_read_data( +#' base_url = "https://bbmc.ouhsc.edu/redcap/api/", +#' token = "9A81268476645C4E5F03428B8AC3AA7B", +#' id_position = 1L +#' ) +#' } #' redcap_read_data <- function(base_url, token, @@ -98,6 +119,17 @@ redcap_read_data <- function(base_url, #' data with only the records and fields of interest and its associated #' metadata. #' @keywords internal +#' @examples +#' \dontrun{ +#' result <- redcap_read_rows_columns( +#' base_url = "https://bbmc.ouhsc.edu/redcap/api/", +#' token = "9A81268476645C4E5F03428B8AC3AA7B", +#' fields = c("record_id", "name_first", "age", "bmi"), +#' records = c("1", "3", "5"), +#' id_position = 1L, +#' id_col_name = NULL +#' ) +#' } #' redcap_read_rows_columns <- function(base_url, token, @@ -156,6 +188,15 @@ redcap_read_rows_columns <- function(base_url, #' @return a `list` of 2 elements of type `data.frame` that contain the project #' data with the fields of interest and its associated metadata. #' @keywords internal +#' @examples +#' \dontrun{ +#' result <- redcap_read_fields( +#' base_url = "https://bbmc.ouhsc.edu/redcap/api/", +#' token = "9A81268476645C4E5F03428B8AC3AA7B", +#' fields = c("record_id", "name_first", "age", "bmi"), +#' id_position = 1L +#' ) +#' } #' redcap_read_fields <- function(base_url, token, @@ -192,6 +233,16 @@ redcap_read_fields <- function(base_url, #' @return a `list` of 2 elements of type `data.frame` that contain the project #' data with the records of interest and its associated metadata. #' @keywords internal +#' @examples +#' \dontrun{ +#' result <- redcap_read_records( +#' base_url = "https://bbmc.ouhsc.edu/redcap/api/", +#' token = "9A81268476645C4E5F03428B8AC3AA7B", +#' records = c("1", "2", "3"), +#' id_position = 1L, +#' id_col_name = NULL +#' ) +#' } #' redcap_read_records <- function(base_url, token, diff --git a/R/read_from_redcap.R b/R/read_from_redcap.R index f9938f46..f551e029 100644 --- a/R/read_from_redcap.R +++ b/R/read_from_redcap.R @@ -1,5 +1,5 @@ #' Import data from REDCap -#' + #' @param base_url the URI of the server #' @param token the user-specific string that serves as the password for a #' project @@ -17,10 +17,10 @@ #' redcap_data <- read_from_redcap( #' base_url = "https://bbmc.ouhsc.edu/redcap/api/", #' token = "9A81268476645C4E5F03428B8AC3AA7B", -#' id_position = 1, -#' id_col_name = NULL, #' records = NULL, -#' fields = NULL +#' fields = NULL, +#' id_position = 1, +#' id_col_name = NULL #' ) #' } #' @returns a `list` of 2 elements of type `data.frame`. They include a data @@ -29,10 +29,10 @@ #' read_from_redcap <- function(base_url, token, - id_position = 1L, - id_col_name = NULL, records = NULL, - fields = NULL) { + fields = NULL, + id_position = 1L, + id_col_name = NULL) { # check input variables checkmate::assert_character(token, n.chars = 32L, len = 1L, null.ok = FALSE, diff --git a/R/read_servers.R b/R/read_servers.R index f1dd3604..dca25640 100644 --- a/R/read_servers.R +++ b/R/read_servers.R @@ -4,6 +4,7 @@ #' Importing data stored in DBMS into R requires the installation #' of the appropriate `driver` that is compatible with the server version #' hosting the database. See the `vignette` for how to install the driver +#' #' @param base_url the name of the host server #' @param user_name the user name #' @param password the user password @@ -13,7 +14,7 @@ #' @param src an SQL query or a vector of table names from #' the project or database. When this is not specified, the function will #' extract data from all tables in the database. -#' @param driver_name the name of the MS driver. use `odbc::odbcListDrivers()` +#' @param driver_name the name of the MS driver. Use `odbc::odbcListDrivers()` #' to display the list of installed drivers #' @param records a vector or a comma-separated string of subset of subject IDs. #' When specified, only the records that correspond to these subjects will diff --git a/R/read_servers_helpers.R b/R/read_servers_helpers.R index ebdc3386..fc07db94 100644 --- a/R/read_servers_helpers.R +++ b/R/read_servers_helpers.R @@ -66,13 +66,6 @@ sql_connect_to_server <- function(base_url, #' #' @return a `character` with the identified tables name(s) from the SQL query #' -#' @examples -#' \dontrun{ -#' table_name <- sql_identify_table_name( -#' query = "select * from author", -#' tables = c("family_author", "author", "test") -#' ) -#' } #' @keywords internal #' sql_identify_table_name <- function(query, @@ -424,7 +417,7 @@ sql_select_records_and_fields <- function(table, })) field <- unlist(strsplit(field, ",", fixed = TRUE)) } - res <- res %>% dplyr::select(dplyr::all_of(field)) + res <- res %>% dplyr::select(dplyr::all_of(field)) pool::poolClose(con) res } @@ -440,16 +433,17 @@ sql_select_records_and_fields <- function(table, #' #' @return prints the first 5 rows of the specified table. #' +#' @export #' @examples #' \dontrun{ -#' visualise_table( -#' data_source = "mysql-rfam-public.ebi.ac.uk", -#' credentials_file = system.file("extdata", "test.ini", package = "readepi"), -#' from = "author", -#' driver_name = "" -#' ) +#' result <- visualise_table( +#' data_source = "mysql-rfam-public.ebi.ac.uk", +#' credentials_file = system.file("extdata", "test.ini", +#' package = "readepi"), +#' from = "author", +#' driver_name = "" +#' ) #' } -#' @export #' visualise_table <- function(data_source, credentials_file, @@ -472,7 +466,7 @@ visualise_table <- function(data_source, query <- ifelse(credentials[["dbms"]] == "MySQL", sprintf("select * from %s limit 5", from), sprintf("select top 5 * from %s", from)) - res <- DBI::dbGetQuery(con, query) + res <- DBI::dbGetQuery(con, query) pool::poolClose(con) print(res) } diff --git a/R/readepi.R b/R/readepi.R index edf7b1fa..f356c712 100644 --- a/R/readepi.R +++ b/R/readepi.R @@ -16,6 +16,7 @@ #' @param ... additional arguments passed to the `readepi()` function. These are #' enumerated and described in the vignette. #' +#' @returns a `list` of 1 or several object(s) of type `data frame`. #' @examples #' # reading from a MySQL server #' \dontrun{ @@ -26,7 +27,6 @@ #' from = "author" #' ) #' } -#' @returns a `list` of 1 or several object(s) of type `data frame`. #' @export readepi <- function(data_source = NULL, records = NULL, diff --git a/R/readepi_helpers.R b/R/readepi_helpers.R index a68e2522..25553e8a 100644 --- a/R/readepi_helpers.R +++ b/R/readepi_helpers.R @@ -56,16 +56,17 @@ read_credentials <- function(file_path, base_url) { #' #' @return a `list` of 8 elements of type `character` and `numeric` that will be #' used for importing data from Fingertips +#' @keywords internal #' @examples #' \dontrun{ -#' args_list <- fingertips_get_args( -#' list( -#' indicator_id = 90362, -#' area_type_id = 202 +#' res <- fingertips_get_args( +#' list(indicator_id = 90362L, +#' area_type_id = 202L, +#' indicator_name = "Healthy life expectancy at birth", +#' profile_id = 19L) #' ) -#' ) #' } -#' @keywords internal +#' fingertips_get_args <- function(args_list = list(indicator_id = NULL, indicator_name = NULL, diff --git a/R/show_example_file.R b/R/show_example_file.R index 52f9a32e..b9e12eaf 100644 --- a/R/show_example_file.R +++ b/R/show_example_file.R @@ -1,7 +1,9 @@ #' Display the structure of the credentials file +#' #' @return Displays the content of the template credential file. #' @examples #' show_example_file() +#' #' @export #' @importFrom utils read.table #' diff --git a/R/show_tables.R b/R/show_tables.R index 593247bf..b97f3209 100644 --- a/R/show_tables.R +++ b/R/show_tables.R @@ -10,8 +10,7 @@ #' \dontrun{ #' show_tables( #' data_source = "mysql-rfam-public.ebi.ac.uk", -#' credentials_file = system.file("extdata", "test.ini", -#' package = "readepi"), +#' credentials_file = system.file("extdata", "test.ini", package = "readepi"), #' driver_name = "" #' ) #' } diff --git a/README.html b/README.html deleted file mode 100644 index 557973f1..00000000 --- a/README.html +++ /dev/null @@ -1,445 +0,0 @@ - - - - - - - - - -readme - - - - - - - - - - - - - - - - - - - -
- -
- - - - - - - - -
-

readepi: Importing data from health information systems

- -

License: MIT R-CMD-check Codecov test coverage lifecycle-concept

-

{readepi} is an R package for reading data from several health information systems (HIS) including public repositories and relational database management systems (RDBMS). {readepi} currently supports reading data from the followings:

-
    -
  • RDBMS such as MS SQL, MySQL, and PostgreSQL. 
  • -
  • REDCap: a secure web application for building and managing online surveys and databases
    -
  • -
  • DHIS2: an open source and web-based platform for managing health information.
  • -
  • Fingertips: a repository of public health indicators in England.
  • -
-

{readepi} returns a list object containing one or more data frames, and has a number of auxiliary functions manipulating the imported dataset.

-

{readepi} is developed by Epiverse-TRACE team at the Medical Research Council Unit The Gambia at the London School of Hygiene & Tropical Medicine.

-
-

Installation

-

You can install the development version of {readepi} from GitHub with:

-
if (!require("pak")) install.packages("pak")
-pak::pak("epiverse-trace/readepi")
-library(readepi)
-
-
-

Quick start

-

The main function in {readepi} is readepi(), which reads data from a specified source. The basic arguments of the readepi() function are: a string of URL-link to the API, credential file, and other specific arguments that depend on the data source (see the vignette for more details). The examples below show how to use the readepi() function to import data from a variety of sources.

-
-

Reading data from RDBMS

-

readepi() function requires the followings to reading data from a RDBMS:

-
    -
  1. A MS SQL driver that is compatible with the version of RDBMS of interest. The vignette describes how to install the appropriate driver for each database management system.
    -
  2. -
  3. Valid credentials to access the server. The user credential details are expected to be stored in a file that will be supplied as an argument of the readepi() function. Use the show_example_file() function to visualize the structure of template credential file.
  4. -
-

Users can read data from a RDBMS by providing the details of the tables of interest or an SQL query (for more information, see the vignette).

-
# DEFINE THE PATH TO THE CREDENTIAL FILE
-credentials_file <- system.file("extdata", "test.ini", package = "readepi")
-
-# DISPLAY THE STRUCTUTRE OF THE TEMPLATE CREDENTIAL FILE
-show_example_file()
-
-# READING FILE FROM A PROJECT IN A REDCap DATABASE
-dat <- readepi(
-  data_source      = "https://bbmc.ouhsc.edu/redcap/api/",
-  credentials_file = credentials_file
-)
-project_data     <- dat$data # accessing the actual data
-project_metadeta <- dat$metadata # accessing the metadata associated with project
-
-# VIEWING THE LIST OF ALL TABLES IN A MySQL DATABASE
-show_tables(
-  data_source      = "mysql-rfam-public.ebi.ac.uk",
-  credentials_file = credentials_file,
-  driver_name      = "" # note that this example MySQL server does not require a driver
-)
-
-# VISUAIZE FIRST 5 ROWS OF THE TABLE 'AUTHOR'
-visualise_table(
-  data_source      = "mysql-rfam-public.ebi.ac.uk",
-  credentials_file = credentials_file,
-  from             = "author", # this is the table name
-  driver_name      = ""
-)
-
-# READING ALL FILEDS AND RECORDS FROM A MySQL SERVER
-dat <- readepi(
-  data_source      = "mysql-rfam-public.ebi.ac.uk",
-  credentials_file = credentials_file,
-  from             = "author", # this is the table name
-  driver_name      = ""
-)
-
-
-

Reading data from HIS

-
# READING DATA FROM DHIS2
-dat <- readepi(
-  data_source        = "https://play.dhis2.org/dev",
-  credentials_file   = credentials_file,
-  dataset            = "pBOMPrpg1QX",
-  organisation_unit  = "DiszpKrYNg8",
-  data_element_group = NULL,
-  start_date         = "2014",
-  end_date           = "2023"
-)
-
-
-

Reading data from Fingertips

-
# READING DATA FROM THE FINGERTIPS REPOSITORY
-dat <- readepi(
-  indicator_id        = 90362,
-  area_type_id        = 202,
-  parent_area_type_id = 6 # optional
-)
-
-
-
-

Package Vignettes

-

The vignette of the {readepi} package contains detailed illustrations about the use of each function and the description of every argument. This can be accessed by typing the command below:

-
# OPEN THE VIGNETTE WITHIN RSTUDIO
-vignette("readepi")
-
-# OPEN THE VIGNETTE IN YOUR WEB BROWSER.
-browseVignettes("readepi")
-
-
-

Development

-
-

Lifecycle

-

This package is currently a maturing, as defined by the RECON software lifecycle. This means that it can be used in production with the understanding that the interface may still undergo minor changes.

-
-
-

Contributions

-

Contributions are welcome via pull requests.

-
-
-

Code of Conduct

-

Please note that the {{ packagename }} project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

-
-
-
- -
- - -
- - - - \ No newline at end of file diff --git a/README.md b/README.md index e5cfbb28..a7c4ac13 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ -# readepi: Importing data from health information systems +# readepi: Read data from health information systems @@ -18,22 +18,30 @@ coverage](https://codecov.io/gh/epiverse-trace/readepi/branch/main/graph/badge.s **{readepi}** is an R package for reading data from several health -information systems (HIS) including public repositories and relational -database management systems (RDBMS). **{readepi}** currently supports reading data from the followings: +information systems (HIS) including public repositories, relational +database management systems (RDBMS). -- RDBMS such as MS SQL, MySQL, and PostgreSQL.  -- [REDCap](https://projectredcap.org/software/): a secure web application for building and managing +**{readepi}** currently supports reading data from the followings: + +- RDBMS (Relational Database Management Systems) such as MS SQL, MySQL, + and PostgreSQL  +- [REDCap](https://projectredcap.org/software/): Research Electronic + Data Capture - a secure web application for building and managing online surveys and databases - [DHIS2](https://dhis2.org/about/): an open source and web-based - platform for managing health information. + platform for managing health information - [Fingertips](https://fingertips.phe.org.uk/): a repository of public - health indicators in England. + health indicators in England -**{readepi}** returns a list object containing one or more data frames, and has a number of auxiliary functions manipulating the imported dataset. +**{readepi}** returns a list object containing one or more data frames. +**{readepi}** also has a number of auxiliary functions that allow +importing a subset of the original dataset. **{readepi}** is developed by [Epiverse-TRACE](https://data.org/initiatives/epiverse/) team at the -[Medical Research Council Unit The Gambia at the London School of Hygiene & Tropical Medicine](https://www.lshtm.ac.uk/research/units/mrc-gambia). +[Medical Research Center, The Gambia unit at London School of Hygiene +and Tropical +Medicine](https://www.lshtm.ac.uk/research/units/mrc-gambia). ## Installation @@ -48,22 +56,26 @@ library(readepi) ## Quick start -The main function in **{readepi}** is `readepi()`, which reads data from a -specified source. The basic arguments of the `readepi()` function are: a string of URL-link to the API, credential file, and other specific arguments that depend on the data source (see the **vignette** for more +The main function in **{readepi}** is `readepi()`. It reads data from a +specified source. The `readepi()` function accepts a user-supplied +string (the API’s URL) as argument. Other specific arguments can be +provided depending on the data source (see the **vignette** for more details). The examples below show how to use the `readepi()` function to import data from a variety of sources. -### Reading data from RDBMS +### Reading data from RDBMS and HIS -`readepi()` function requires the followings to reading data from a RDBMS: +The `readepi()` function can import data from a variety of RDBMS, +including MS SQL, MySQL, and PostgreSQL. Reading data from a RDBMS +requires the following: -1. A MS SQL driver that is compatible with the version of RDBMS of +1. A MS SQL driver that is compatible with the version of DBMS of interest. The **vignette** describes how to install the appropriate driver for each database management system. -2. Valid credentials to access the server. The user credential details +2. Valid Credentials to access the server. The user credential details are expected to be stored in a file that will be supplied as an argument of the `readepi()` function. Use the `show_example_file()` - function to visualize the structure of template credential file. + function to visualize the structure of the template credential file. Users can read data from a RDBMS by providing the details of the tables of interest or an SQL query (for more information, see the @@ -106,10 +118,7 @@ dat <- readepi( from = "author", # this is the table name driver_name = "" ) -``` -### Reading data from HIS -```r # READING DATA FROM DHIS2 dat <- readepi( data_source = "https://play.dhis2.org/dev", @@ -120,10 +129,7 @@ dat <- readepi( start_date = "2014", end_date = "2023" ) -``` -### Reading data from Fingertips -```r # READING DATA FROM THE FINGERTIPS REPOSITORY dat <- readepi( indicator_id = 90362, diff --git a/_pkgdown.yml b/_pkgdown.yml index 301b50c0..dcb16cd3 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -17,7 +17,7 @@ reference: - subtitle: Fingertips - contents: - starts_with("fingertips_", internal = TRUE) - - read_from_fingertips + - ends_with("fingertips", internal = TRUE) - subtitle: REDCap - contents: diff --git a/man/dhis2_get_relevant_attributes.Rd b/man/dhis2_get_relevant_attributes.Rd index 0e6d8343..4fae5046 100644 --- a/man/dhis2_get_relevant_attributes.Rd +++ b/man/dhis2_get_relevant_attributes.Rd @@ -35,11 +35,11 @@ Get the relevant dataset \examples{ \dontrun{ result <- dhis2_get_relevant_attributes( - base_url = "https://play.dhis2.org/dev/", - user_name = "admin", - password = "district", + base_url = "https://play.dhis2.org/dev/", + user_name = "admin", + password = "district", attribute_id = "pBOMPrpg1QX,BfMAe6Itzgt", - which = "dataSets" + which = "dataSets" ) } } diff --git a/man/dhis2_login.Rd b/man/dhis2_login.Rd index 7ab1e303..68a994bf 100644 --- a/man/dhis2_login.Rd +++ b/man/dhis2_login.Rd @@ -17,11 +17,20 @@ dhis2_login(base_url, user_name, password) a message if the dhis2_login was successful, throws an error otherwise. -a message if the login was successfull, thows an error otherwise. +a message if the login was successful, throws an error otherwise. } \description{ If the user were granted with access to the API, this will return a message specifying that the user was successfully connected. Otherwise, it will throw an error message. } +\examples{ +\dontrun{ + dhis2_login( + base_url = file.path("https:/", "play.dhis2.org", "dev"), + user_name = "admin", + password = "district" + ) +} +} \keyword{internal} diff --git a/man/dhis2_make_api_request.Rd b/man/dhis2_make_api_request.Rd index 1b87bc88..242d22da 100644 --- a/man/dhis2_make_api_request.Rd +++ b/man/dhis2_make_api_request.Rd @@ -28,5 +28,16 @@ interest. } \description{ Make an API request to the target DHIS2 system +} +\examples{ +\dontrun{ + response <- dhis2_make_api_request( + base_url = file.path("https:/", "play.dhis2.org", "dev"), + user_name = "admin", + password = "district", + which = "dataElements" + ) +} + } \keyword{internal} diff --git a/man/dhis2_subset_fields.Rd b/man/dhis2_subset_fields.Rd index b346bde6..a37f3804 100644 --- a/man/dhis2_subset_fields.Rd +++ b/man/dhis2_subset_fields.Rd @@ -23,7 +23,7 @@ Subset fields when reading from DHIS2 results <- dhis2_subset_fields( data = readepi( credentials_file = system.file("extdata", "test.ini", - package = "readepi"), + package = "readepi"), data_source = "https://play.dhis2.org/dev", dataset = "pBOMPrpg1QX,BfMAe6Itzgt", organisation_unit = "DiszpKrYNg8", diff --git a/man/dhis2_subset_records.Rd b/man/dhis2_subset_records.Rd index 1eb4c436..676ede0f 100644 --- a/man/dhis2_subset_records.Rd +++ b/man/dhis2_subset_records.Rd @@ -25,8 +25,7 @@ Subset a specified set of records from a dataset imported from DHIS2 result <- dhis2_subset_records( data = readepi( credentials_file = system.file("extdata", "test.ini", - package = "readepi" - ), + package = "readepi"), data_source = "https://play.dhis2.org/dev", dataset = "pBOMPrpg1QX", organisation_unit = "DiszpKrYNg8", diff --git a/man/fingertips_get_args.Rd b/man/fingertips_get_args.Rd index 1abc6cf9..b54804c1 100644 --- a/man/fingertips_get_args.Rd +++ b/man/fingertips_get_args.Rd @@ -22,12 +22,13 @@ Get arguments for reading from Fingertips } \examples{ \dontrun{ -args_list <- fingertips_get_args( - list( - indicator_id = 90362, - area_type_id = 202 + res <- fingertips_get_args( + list(indicator_id = 90362L, + area_type_id = 202L, + indicator_name = "Healthy life expectancy at birth", + profile_id = 19L) ) -) } + } \keyword{internal} diff --git a/man/fingertips_get_profile_name.Rd b/man/fingertips_get_profile_name.Rd index c48952a5..481adb9d 100644 --- a/man/fingertips_get_profile_name.Rd +++ b/man/fingertips_get_profile_name.Rd @@ -25,5 +25,19 @@ the \verb{profile name} and their correspondent indexes. } \description{ Get profile name from Fingertips +} +\examples{ +\dontrun{ + res <- fingertips_get_profile_name( + profile_id = 19L, + profile_name = "Public Health Outcomes Framework", + metadata = list( + indicator_profile_domain = fingertipsR::indicators(), + indicator_ids_names = fingertipsR::indicators_unique(), + area_type = fingertipsR::area_types() + ) + ) +} + } \keyword{internal} diff --git a/man/read_from_fingertips.Rd b/man/read_from_fingertips.Rd deleted file mode 100644 index 05d7ad64..00000000 --- a/man/read_from_fingertips.Rd +++ /dev/null @@ -1,63 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/read_from_fingertips.R -\name{read_from_fingertips} -\alias{read_from_fingertips} -\title{Read from Fingertips} -\usage{ -read_from_fingertips( - indicator_id = 90362L, - indicator_name = NULL, - area_type_id = 202L, - parent_area_type_id = NULL, - profile_id = NULL, - profile_name = NULL, - domain_id = NULL, - domain_name = NULL, - fields = NULL, - records = NULL, - id_position = NULL, - id_col_name = "AreaCode" -) -} -\arguments{ -\item{indicator_id}{a numeric vector of indicator IDs} - -\item{indicator_name}{a vector of a comma-separated list of indicator names} - -\item{area_type_id}{a vector of area type IDs} - -\item{parent_area_type_id}{a vector of parent area type IDs} - -\item{profile_id}{a vector of profile IDs} - -\item{profile_name}{a vector or a comma-separated list of profile names} - -\item{domain_id}{a vector of domain IDs} - -\item{domain_name}{a vector or a comma-separated list of domain names} - -\item{fields}{a vector or a comma-separated string of column names. -If provided, only those columns will be imported.} - -\item{records}{a vector or a comma-separated string of records. -When specified, only these records will be imported.} - -\item{id_position}{the column position of the variable that unique identifies -the subjects. When the name of the column with the subject IDs is known, -this can be provided using the \code{id_col_name} argument} - -\item{id_col_name}{the column name with the subject IDs.} -} -\value{ -a \code{list} of 1 element of type \code{data.frame}. This contains the -imported dataset of interest. -} -\description{ -Read from Fingertips -} -\examples{ -\dontrun{ - data <- read_from_fingertips(indicator_id = 90362, area_type_id = 202) -} -} -\keyword{internal} diff --git a/man/read_from_redcap.Rd b/man/read_from_redcap.Rd index 1ecb2c72..41ced196 100644 --- a/man/read_from_redcap.Rd +++ b/man/read_from_redcap.Rd @@ -7,10 +7,10 @@ read_from_redcap( base_url, token, - id_position = 1L, - id_col_name = NULL, records = NULL, - fields = NULL + fields = NULL, + id_position = 1L, + id_col_name = NULL ) } \arguments{ @@ -19,18 +19,18 @@ read_from_redcap( \item{token}{the user-specific string that serves as the password for a project} -\item{id_position}{the column position of the variable that unique identifies -the subjects. When the column name with the subject IDs is known, use -the \code{id_col_name} argument instead. default is 1} - -\item{id_col_name}{the column name with the subject IDs} - \item{records}{a vector or a comma-separated string of subset of subject IDs. When specified, only the records that correspond to these subjects will be imported.} \item{fields}{a vector or a comma-separated string of column names. If provided, only those columns will be imported.} + +\item{id_position}{the column position of the variable that unique identifies +the subjects. When the column name with the subject IDs is known, use +the \code{id_col_name} argument instead. default is 1} + +\item{id_col_name}{the column name with the subject IDs} } \value{ a \code{list} of 2 elements of type \code{data.frame}. They include a data @@ -44,10 +44,10 @@ Import data from REDCap redcap_data <- read_from_redcap( base_url = "https://bbmc.ouhsc.edu/redcap/api/", token = "9A81268476645C4E5F03428B8AC3AA7B", - id_position = 1, - id_col_name = NULL, records = NULL, - fields = NULL + fields = NULL, + id_position = 1, + id_col_name = NULL ) } } diff --git a/man/redcap_import_data.Rd b/man/redcap_import_data.Rd index 0fec05f1..36cb9bbd 100644 --- a/man/redcap_import_data.Rd +++ b/man/redcap_import_data.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/read_from_redcap-helpers.R \name{redcap_import_data} \alias{redcap_import_data} -\title{Import data from REDCap under all scenari} +\title{Import data from REDCap under all scenario} \usage{ redcap_import_data( base_url, @@ -37,5 +37,20 @@ This is a wrapper across all the use case of reading data from REDCap i.e. around the function that all records and fields from the project, around the function that read specific records/fields or both at the same time +} +\examples{ +\dontrun{ + result <- redcap_import_data( + base_url = file.path("https:/", "bbmc.ouhsc.edu", + "redcap", "api", ""), + token = "9A81268476645C4E5F03428B8AC3AA7B", + records = c("1", "3", "5"), + fields = c("record_id", "name_first", "age", "bmi"), + id_position = 1L, + id_col_name = NULL + ) +} + + } \keyword{internal} diff --git a/man/redcap_read_data.Rd b/man/redcap_read_data.Rd index 8e19eb23..a2e3c8f8 100644 --- a/man/redcap_read_data.Rd +++ b/man/redcap_read_data.Rd @@ -21,5 +21,15 @@ data and its associated metadata. } \description{ Read all rows and columns from redcap +} +\examples{ +\dontrun{ + result <- redcap_read_data( + base_url = "https://bbmc.ouhsc.edu/redcap/api/", + token = "9A81268476645C4E5F03428B8AC3AA7B", + id_position = 1L + ) +} + } \keyword{internal} diff --git a/man/redcap_read_fields.Rd b/man/redcap_read_fields.Rd index b7b40abf..2c14dd21 100644 --- a/man/redcap_read_fields.Rd +++ b/man/redcap_read_fields.Rd @@ -23,5 +23,16 @@ data with the fields of interest and its associated metadata. } \description{ Subset fields from a REDCap project +} +\examples{ +\dontrun{ + result <- redcap_read_fields( + base_url = "https://bbmc.ouhsc.edu/redcap/api/", + token = "9A81268476645C4E5F03428B8AC3AA7B", + fields = c("record_id", "name_first", "age", "bmi"), + id_position = 1L + ) +} + } \keyword{internal} diff --git a/man/redcap_read_records.Rd b/man/redcap_read_records.Rd index b2a5013d..aba48e78 100644 --- a/man/redcap_read_records.Rd +++ b/man/redcap_read_records.Rd @@ -31,5 +31,17 @@ data with the records of interest and its associated metadata. } \description{ Subset records from a REDCap project +} +\examples{ +\dontrun{ + result <- redcap_read_records( + base_url = "https://bbmc.ouhsc.edu/redcap/api/", + token = "9A81268476645C4E5F03428B8AC3AA7B", + records = c("1", "2", "3"), + id_position = 1L, + id_col_name = NULL + ) +} + } \keyword{internal} diff --git a/man/redcap_read_rows_columns.Rd b/man/redcap_read_rows_columns.Rd index 0cf3515b..b4d728ee 100644 --- a/man/redcap_read_rows_columns.Rd +++ b/man/redcap_read_rows_columns.Rd @@ -35,5 +35,18 @@ metadata. } \description{ Subset records and columns from a REDCap project +} +\examples{ +\dontrun{ + result <- redcap_read_rows_columns( + base_url = "https://bbmc.ouhsc.edu/redcap/api/", + token = "9A81268476645C4E5F03428B8AC3AA7B", + fields = c("record_id", "name_first", "age", "bmi"), + records = c("1", "3", "5"), + id_position = 1L, + id_col_name = NULL + ) +} + } \keyword{internal} diff --git a/man/show_example_file.Rd b/man/show_example_file.Rd index d8922064..b15f3db1 100644 --- a/man/show_example_file.Rd +++ b/man/show_example_file.Rd @@ -14,4 +14,5 @@ Display the structure of the credentials file } \examples{ show_example_file() + } diff --git a/man/show_tables.Rd b/man/show_tables.Rd index afe0b48d..b1ac9ded 100644 --- a/man/show_tables.Rd +++ b/man/show_tables.Rd @@ -27,8 +27,7 @@ Display the list of tables in a database \dontrun{ show_tables( data_source = "mysql-rfam-public.ebi.ac.uk", - credentials_file = system.file("extdata", "test.ini", - package = "readepi"), + credentials_file = system.file("extdata", "test.ini", package = "readepi"), driver_name = "" ) } diff --git a/man/sql_identify_table_name.Rd b/man/sql_identify_table_name.Rd index e93ef262..45f91c60 100644 --- a/man/sql_identify_table_name.Rd +++ b/man/sql_identify_table_name.Rd @@ -17,12 +17,4 @@ a \code{character} with the identified tables name(s) from the SQL query \description{ Detect table names from an SQL query } -\examples{ -\dontrun{ -table_name <- sql_identify_table_name( - query = "select * from author", - tables = c("family_author", "author", "test") -) -} -} \keyword{internal} diff --git a/man/sql_server_read_data.Rd b/man/sql_server_read_data.Rd index 9f533648..5baba981 100644 --- a/man/sql_server_read_data.Rd +++ b/man/sql_server_read_data.Rd @@ -28,7 +28,7 @@ sql_server_read_data( \item{dbms}{the SQL server type} -\item{driver_name}{the name of the MS driver. use \code{odbc::odbcListDrivers()} +\item{driver_name}{the name of the MS driver. Use \code{odbc::odbcListDrivers()} to display the list of installed drivers} \item{database_name}{the name of the database that contains the table from diff --git a/man/visualise_table.Rd b/man/visualise_table.Rd index 41eeb886..b3bd3d6e 100644 --- a/man/visualise_table.Rd +++ b/man/visualise_table.Rd @@ -24,11 +24,13 @@ Visualize the first 5 rows of the data from a table } \examples{ \dontrun{ -visualise_table( - data_source = "mysql-rfam-public.ebi.ac.uk", - credentials_file = system.file("extdata", "test.ini", package = "readepi"), - from = "author", - driver_name = "" -) + result <- visualise_table( + data_source = "mysql-rfam-public.ebi.ac.uk", + credentials_file = system.file("extdata", "test.ini", + package = "readepi"), + from = "author", + driver_name = "" + ) } + } diff --git a/tests/testthat/test-read_from_dhis2_helpers.R b/tests/testthat/test-read_from_dhis2_helpers.R index b0bae9c7..fea6f427 100644 --- a/tests/testthat/test-read_from_dhis2_helpers.R +++ b/tests/testthat/test-read_from_dhis2_helpers.R @@ -160,3 +160,21 @@ test_that("dhis2_subset_records sends a warning when the provided record is not id_col_name = "dataElement"), regexp = cat("Assertion on',records,'failed: 'test' is not a valid record.")) # nolint: line_length_linter }) + +test_that("dhis2_subset_records works as expected", { + test <- dhis2_get_attributes_from_user( + args_list = list(dataset = "pBOMPrpg1QX", + start_date = "2014", + end_date = "2023") + ) + expect_type(test, "list") + expect_length(test, 5) + expect_named(test, expected = c("dataset", "organisation_unit", + "data_element_group", "start_date", + "end_date")) + expect_null(test[["organisation_unit"]]) + expect_null(test[["data_element_group"]]) + expect_identical(test[["dataset"]], "pBOMPrpg1QX") + expect_identical(test[["start_date"]], "2014") + expect_identical(test[["end_date"]], "2023") +}) diff --git a/tests/testthat/test-read_servers_helpers.R b/tests/testthat/test-read_servers_helpers.R index 83a09c92..68824dfb 100644 --- a/tests/testthat/test-read_servers_helpers.R +++ b/tests/testthat/test-read_servers_helpers.R @@ -509,3 +509,27 @@ test_that("sql_select_fields_only works as expected", { ) expect_s3_class(result, "data.frame") }) + +test_that("sql_identify_table_and_query works as expected", { + test <- sql_identify_table_and_query( + src = "select * from author", + tables = c("karim", "author", "reviewer") + ) + expect_type(test, "list") + expect_length(test, 2L) + expect_named(test, c("queries", "tables")) + expect_type(test[["queries"]], "character") + expect_null(test[["tables"]]) +}) + +test_that("sql_identify_table_and_query works as expected", { + test <- sql_identify_table_and_query( + src = "author", + tables = c("karim", "author", "reviewer") + ) + expect_type(test, "list") + expect_length(test, 2L) + expect_named(test, c("queries", "tables")) + expect_null(test[["queries"]]) + expect_type(test[["tables"]], "character") +})