diff --git a/DESCRIPTION b/DESCRIPTION index b537d0e..7a4d355 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: NVIdb Title: Tools to facilitate the use of NVI's databases -Version: 0.11.0 -Date: 2024-01-24 +Version: 0.11.1 +Date: 2024-02-05 Authors@R: c(person(given = "Petter", family = "Hopp", diff --git a/NEWS b/NEWS index 47f6041..05ad423 100644 --- a/NEWS +++ b/NEWS @@ -1,9 +1,22 @@ +NVIdb 0.11.1 - (2024-02-05) +---------------------------------------- + +New features: + +- set_disease_parameters now accepts the arguments purpose, FUN and select_statement. + + +Bug fixes: + +- set_disease_parameters now accepts metodekode with 2 digits. + + NVIdb 0.11.0 - (2024-01-24) ---------------------------------------- New features: -- Created `retrieve_PJS_data` to retrieve and standardisation of PJSdata. +- Created `retrieve_PJS_data` to retrieve and standardise PJSdata. - Created `transform_code_values` to easy transform few code combinations into other values. diff --git a/R/build_query_one_disease.R b/R/build_query_one_disease.R index abd67ee..29627b4 100644 --- a/R/build_query_one_disease.R +++ b/R/build_query_one_disease.R @@ -1,25 +1,41 @@ #' @title Builds query for selecting data for one disease from PJS -#' @description Builds the query for selecting all data for one infection/disease within one year from PJS. The input is the analytter -#' for the infectious agent and/or disease, the hensikter and metoder specific for the infection and/or disease. The the query is -#' written in T-SQL as used by MS-SQL. +#' @description Builds the query for selecting all data for one +#' infection/disease within one year from PJS. The input is the +#' analytter for the infectious agent and/or disease, the +#' hensikter and metoder specific for the infection and/or +#' disease. The the query is written in T-SQL as used by MS-SQL. #' -#' @details The function builds the SQL syntax to select all PJS-journals concerning one infection and/o disease from PJS. This is based -#' on selecting all journals with the disease and/or infectious agent analytt in resultat, konklusjon or sakskonklusjon. By this, all -#' journals were the examination have been performed and a result has been entered should be selected. +#' @details The function builds the SQL syntax to select all PJS-journals +#' concerning one infection and/o disease from PJS. This is based +#' on selecting all journals with the disease and/or infectious +#' agent analytt in resultat, konklusjon or sakskonklusjon. By this, +#' all journals were the examination have been performed and a +#' result has been entered should be selected. #' -#' One or more specific hensikter may be input to the selection statement. With specific hensikt is meant a hensikt that will imply -#' that the sample will be examined for the infectious agent or disease. Thereby, the selection will include samples that haven't -#' been set up for examination yet, samples that were unfit for examination and samples for which wrong conclusions have been entered. +#' One or more specific hensikter may be input to the selection +#' statement. With specific hensikt is meant a hensikt that will +#' imply that the sample will be examined for the infectious agent +#' or disease. Thereby, the selection will include samples that +#' haven't been set up for examination yet, samples that were +#' unfit for examination and samples for which wrong conclusions +#' have been entered. #' -#' One or more specific metoder may be input to the selection statement. With specific metode is meant a metode that implies an -#' examination that will give one of the input analytter as a result. Thereby, the query will include samples that have been set up -#' for examination, but haven't been examined yet, samples that were unfit for examination and samples for which wrong results have -#' been entered. +#' One or more specific metoder may be input to the selection +#' statement. With specific metode is meant a metode that implies +#' an examination that will give one of the input analytter as a +#' result. Thereby, the query will include samples that have been +#' set up for examination, but haven't been examined yet, samples +#' that were unfit for examination and samples for which wrong +#' results have been entered. #' -#' To select both the disease analytt and the infectious agent analytt ensures that all journals that have been examined with a result -#' is included in the output. The inclusion of specific hensikter and metoder, if exists, ensures that all journals received with the -#' purpose of examining for the infectious agent and/or disease will be included even if the examination has not been performed. This -#' is important for a full control of all relevant data for an infectious agent and/or disease. +#' To select both the disease analytt and the infectious agent +#' analytt ensures that all journals that have been examined with +#' a result is included in the output. The inclusion of specific +#' hensikter and metoder, if exists, ensures that all journals +#' received with the purpose of examining for the infectious agent +#' and/or disease will be included even if the examination has +#' not been performed. This is important for a full control of +#' all relevant data for an infectious agent and/or disease. #' #' @template build_query_year #' @param analytt [\code{character}]\cr diff --git a/R/set_disease_parameters.R b/R/set_disease_parameters.R index 3d36c32..2a2a8b5 100644 --- a/R/set_disease_parameters.R +++ b/R/set_disease_parameters.R @@ -12,6 +12,12 @@ #' a relevant "utbrudds_ID" and/or specific "metoder." These can be used to select #' saker in PJS and/or to structure and simplify the output from PJS. #' +#' The purpose is a short description of purpose of the selection described by the +#' selection parameters for example "ok_svin_virus" that describes the selection +#' parameters for the OK programme for virus in swine. The purpose is also used as +#' part of the file name for selection_parameters, i.e. "purpose_selection_parameters" +#' and in the annual tables for ok_programmer: Kontrolltabeller for yyyy. +#' #' One or more specific "hensiktkoder" may be input to the selection statement. #' With specific "hensiktkode" is meant a "hensiktkode" that will imply that the sample #' will be examined for specific infectious agent(s) or disease. One or more @@ -39,9 +45,11 @@ #' warning is issued and the input is transferred to \code{include_missing_art} and #' \code{selection_parameters}, respectively. #' +#' @param purpose [\code{character}]\cr +#' A short description of the purpose of the selection, see details. Defaults to NULL. #' @param hensikt2select [\code{character}]\cr #' Specific "hensiktkoder" for the "analytt" in question. If sub-codes should -#' be included, end the code with \%.Defaults to \code{NULL}. +#' be included, end the code with \%. Defaults to \code{NULL}. #' @param hensikt2delete [\code{character}]\cr #' "hensiktkoder" for which saker should be excluded. #' If sub-codes should be included, end the code with \%. Defaults to \code{NULL}. @@ -66,6 +74,14 @@ #' Either the path and file name for an R script that can be sourced and that #' sets the selection parameters or a named list with the selection parameters #' (i.e. equal to the output of this function). Defaults to \code{NULL}. +#' @param FUN [\code{function}]\cr +#' Function to build the selection statement, see +#' \ifelse{html}{\code{\link{retrieve_PJSdata}}}{\code{retrieve_PJSdata}}). +#' Defaults to \code{NULL}. +#' @param select_statement [\code{character(1)}]\cr +#' A written select statement, see +#' \ifelse{html}{\code{\link{retrieve_PJSdata}}}{\code{retrieve_PJSdata}}). +#' Defaults to \code{NULL}. #' @param \dots Other arguments to be passed to `set_disease_parameters`. #' #' @return A named list with selection parameters that can be used to generate @@ -80,7 +96,8 @@ #' hensikt2select = c("0100108018", "0100109003", "0100111003", "0800109"), #' metode2select = c("070070", "070231", "010057", "060265") #' ) -set_disease_parameters <- function(hensikt2select = NULL, +set_disease_parameters <- function(purpose = NULL, + hensikt2select = NULL, hensikt2delete = NULL, utbrudd2select = NULL, metode2select = NULL, @@ -88,15 +105,19 @@ set_disease_parameters <- function(hensikt2select = NULL, analytt2delete = NULL, art2select = NULL, include_missing_art = NULL, + FUN = NULL, + select_statement = NULL, selection_parameters = NULL, ...) { # SET SELECTION PARAMETERS ---- # Vector with possible selection parameter names # missing_art is deprecated - var2select_template <- c("hensikt2select", "hensikt2delete", "utbrudd2select", + var2select_template <- c("purpose", + "hensikt2select", "hensikt2delete", "utbrudd2select", "metode2select", "analytt2select", "analytt2delete", "art2select", - "include_missing_art", "missing_art") + "include_missing_art", "missing_art", + "FUN", "select_statement") # PREPARE ARGUMENTS BEFORE CHECKING ---- if ("file" %in% ...names() & is.null(selection_parameters)) { @@ -165,11 +186,12 @@ set_disease_parameters <- function(hensikt2select = NULL, # checks <- checkmate::makeAssertCollection() # Perform checks + checkmate::assert_string(purpose, null.ok = TRUE, add = checks) NVIcheckmate::assert_non_null(list(analytt2select, hensikt2select, utbrudd2select, unlist(selection_parameters)), add = checks) checkmate::assert_character(hensikt2select, min.chars = 2, max.chars = 15, any.missing = FALSE, null.ok = TRUE, add = checks) checkmate::assert_character(hensikt2delete, min.chars = 2, max.chars = 15, any.missing = FALSE, null.ok = TRUE, add = checks) checkmate::assert_character(utbrudd2select, max.chars = 5, any.missing = FALSE, null.ok = TRUE, add = checks) - checkmate::assert_character(metode2select, n.chars = 6, any.missing = FALSE, null.ok = TRUE, add = checks) + checkmate::assert_character(metode2select, min.chars = 2, max.chars = 6, any.missing = FALSE, null.ok = TRUE, add = checks) checkmate::assert_character(analytt2select, min.chars = 2, max.chars = 20, any.missing = FALSE, null.ok = TRUE, add = checks) checkmate::assert_character(analytt2delete, min.chars = 2, max.chars = 20, any.missing = FALSE, null.ok = TRUE, add = checks) checkmate::assert_character(art2select, min.chars = 2, max.chars = 20, all.missing = FALSE, null.ok = TRUE, add = checks) @@ -178,17 +200,25 @@ set_disease_parameters <- function(hensikt2select = NULL, choices = c("never", "always", "for_selected_hensikt"), add = checks) # } + checkmate::assert_function(FUN, null.ok = TRUE, add = checks) + checkmate::assert(checkmate::check_list(x = select_statement, null.ok = TRUE), + checkmate::check_string(x = select_statement), + combine = "or", + add = checks) # Report check-results checkmate::reportAssertions(checks) # CREATE LIST WITH PARAMETER VALUES ---- - return(list("hensikt2select" = hensikt2select, + return(list("purpose" = purpose, + "hensikt2select" = hensikt2select, "hensikt2delete" = hensikt2delete, "utbrudd2select" = utbrudd2select, "metode2select" = metode2select, "analytt2select" = analytt2select, "analytt2delete" = analytt2delete, "art2select" = art2select, - "include_missing_art" = include_missing_art)) + "include_missing_art" = include_missing_art, + "FUN" = FUN, + "select_statement" = select_statement)) } diff --git a/man/build_query_one_disease.Rd b/man/build_query_one_disease.Rd index 3107ac0..56d822f 100644 --- a/man/build_query_one_disease.Rd +++ b/man/build_query_one_disease.Rd @@ -36,28 +36,44 @@ is the only valid value.} A list with select-statement fom v2_sak_m_res and v_sakskonklusjon to be included in a \code{RODBC::sqlQuery}. } \description{ -Builds the query for selecting all data for one infection/disease within one year from PJS. The input is the analytter - for the infectious agent and/or disease, the hensikter and metoder specific for the infection and/or disease. The the query is - written in T-SQL as used by MS-SQL. +Builds the query for selecting all data for one + infection/disease within one year from PJS. The input is the + analytter for the infectious agent and/or disease, the + hensikter and metoder specific for the infection and/or + disease. The the query is written in T-SQL as used by MS-SQL. } \details{ -The function builds the SQL syntax to select all PJS-journals concerning one infection and/o disease from PJS. This is based - on selecting all journals with the disease and/or infectious agent analytt in resultat, konklusjon or sakskonklusjon. By this, all - journals were the examination have been performed and a result has been entered should be selected. +The function builds the SQL syntax to select all PJS-journals + concerning one infection and/o disease from PJS. This is based + on selecting all journals with the disease and/or infectious + agent analytt in resultat, konklusjon or sakskonklusjon. By this, + all journals were the examination have been performed and a + result has been entered should be selected. - One or more specific hensikter may be input to the selection statement. With specific hensikt is meant a hensikt that will imply - that the sample will be examined for the infectious agent or disease. Thereby, the selection will include samples that haven't - been set up for examination yet, samples that were unfit for examination and samples for which wrong conclusions have been entered. + One or more specific hensikter may be input to the selection + statement. With specific hensikt is meant a hensikt that will + imply that the sample will be examined for the infectious agent + or disease. Thereby, the selection will include samples that + haven't been set up for examination yet, samples that were + unfit for examination and samples for which wrong conclusions + have been entered. - One or more specific metoder may be input to the selection statement. With specific metode is meant a metode that implies an - examination that will give one of the input analytter as a result. Thereby, the query will include samples that have been set up - for examination, but haven't been examined yet, samples that were unfit for examination and samples for which wrong results have - been entered. + One or more specific metoder may be input to the selection + statement. With specific metode is meant a metode that implies + an examination that will give one of the input analytter as a + result. Thereby, the query will include samples that have been + set up for examination, but haven't been examined yet, samples + that were unfit for examination and samples for which wrong + results have been entered. - To select both the disease analytt and the infectious agent analytt ensures that all journals that have been examined with a result - is included in the output. The inclusion of specific hensikter and metoder, if exists, ensures that all journals received with the - purpose of examining for the infectious agent and/or disease will be included even if the examination has not been performed. This - is important for a full control of all relevant data for an infectious agent and/or disease. + To select both the disease analytt and the infectious agent + analytt ensures that all journals that have been examined with + a result is included in the output. The inclusion of specific + hensikter and metoder, if exists, ensures that all journals + received with the purpose of examining for the infectious agent + and/or disease will be included even if the examination has + not been performed. This is important for a full control of + all relevant data for an infectious agent and/or disease. } \examples{ # SQL-select query for Pancreatic disease (PD) diff --git a/man/set_disease_parameters.Rd b/man/set_disease_parameters.Rd index 30b2f49..ec2adb8 100644 --- a/man/set_disease_parameters.Rd +++ b/man/set_disease_parameters.Rd @@ -5,6 +5,7 @@ \title{Sets disease selection parameters} \usage{ set_disease_parameters( + purpose = NULL, hensikt2select = NULL, hensikt2delete = NULL, utbrudd2select = NULL, @@ -13,14 +14,19 @@ set_disease_parameters( analytt2delete = NULL, art2select = NULL, include_missing_art = NULL, + FUN = NULL, + select_statement = NULL, selection_parameters = NULL, ... ) } \arguments{ +\item{purpose}{[\code{character}]\cr +A short description of the purpose of the selection, see details. Defaults to NULL.} + \item{hensikt2select}{[\code{character}]\cr Specific "hensiktkoder" for the "analytt" in question. If sub-codes should - be included, end the code with \%.Defaults to \code{NULL}.} + be included, end the code with \%. Defaults to \code{NULL}.} \item{hensikt2delete}{[\code{character}]\cr "hensiktkoder" for which saker should be excluded. @@ -49,6 +55,16 @@ Should missing art be included. Must be one of c("never", "always", "for_selecte If NULL, it is set to "always" when \code{art2select} includes NA, else it is set to "never". Defaults to \code{NULL}.} +\item{FUN}{[\code{function}]\cr +Function to build the selection statement, see + \ifelse{html}{\code{\link{retrieve_PJSdata}}}{\code{retrieve_PJSdata}}). + Defaults to \code{NULL}.} + +\item{select_statement}{[\code{character(1)}]\cr +A written select statement, see + \ifelse{html}{\code{\link{retrieve_PJSdata}}}{\code{retrieve_PJSdata}}). + Defaults to \code{NULL}.} + \item{selection_parameters}{[\code{character(1)}]\cr Either the path and file name for an R script that can be sourced and that sets the selection parameters or a named list with the selection parameters @@ -75,6 +91,12 @@ Saker in PJS that concern one infection / disease can be characterised a relevant "utbrudds_ID" and/or specific "metoder." These can be used to select saker in PJS and/or to structure and simplify the output from PJS. + The purpose is a short description of purpose of the selection described by the + selection parameters for example "ok_svin_virus" that describes the selection + parameters for the OK programme for virus in swine. The purpose is also used as + part of the file name for selection_parameters, i.e. "purpose_selection_parameters" + and in the annual tables for ok_programmer: Kontrolltabeller for yyyy. + One or more specific "hensiktkoder" may be input to the selection statement. With specific "hensiktkode" is meant a "hensiktkode" that will imply that the sample will be examined for specific infectious agent(s) or disease. One or more diff --git a/tests/testthat/test_PJS_code_description.R b/tests/testthat/test_PJS_code_description.R index 08455b0..66d4b7f 100644 --- a/tests/testthat/test_PJS_code_description.R +++ b/tests/testthat/test_PJS_code_description.R @@ -245,4 +245,54 @@ test_that("Backward translation from description to code", { # # c("", "", "", "", "", "", "", "", "", "")) # }) +test_that("errors for add_PJS_code_description", { + + linewidth <- options("width") + options(width = 80) + + # skip if no connection to 'FAG' have been established + skip_if_not(dir.exists(set_dir_NVI("FAG"))) + + # Reads translation table for PJS-codes + PJS_codes_2_text <- read_PJS_codes_2_text() + + testdata <- as.data.frame(list("hensiktkode" = c("01001", "01002"), + "metodekode" = c("010001", "010002"), + "ansvarlig_seksjon" = c("01", "02"))) + + expect_error(add_PJS_code_description("testdata", + translation_table = PJS_codes_2_text, + code_colname = c("hensiktkode", "metodekode", "ansvarlig_seksjon"), + PJS_variable_type = c("hensikt", "metode", "seksjon"), + new_column = c("hensikt", "metode", "seksjon")), + regexp = "Variable 'data': Must be of type 'data.frame', not 'character'.", + fixed = TRUE) + + expect_error(add_PJS_code_description(testdata, + translation_table = PJS_codes_2_text, + code_colname = c("hensiktkoder"), + PJS_variable_type = c("hensikt"), + new_column = c("hensikt")), + regexp = "but 'hensiktkoder' is not a column in the data.", + fixed = TRUE) + + expect_error(add_PJS_code_description(testdata, + translation_table = PJS_codes_2_text, + code_colname = c("hensiktkode"), + PJS_variable_type = c("hensikter"), + new_column = c("hensikt")), + regexp = "Variable 'PJS_variable_type': Must be a subset of", + fixed = TRUE) + + expect_error(add_PJS_code_description(testdata, + translation_table = PJS_codes_2_text, + code_colname = c("hensiktkode"), + PJS_variable_type = c("hensikt"), + new_column = c("metodekode")), + regexp = "The column name(s): 'metodekode' already exist in 'testdata`.", + fixed = TRUE) + + options(width = unlist(linewidth)) +}) + RODBC::odbcCloseAll() diff --git a/tests/testthat/test_Prodtilskudd.R b/tests/testthat/test_Prodtilskudd.R index 53a23cf..385c846 100644 --- a/tests/testthat/test_Prodtilskudd.R +++ b/tests/testthat/test_Prodtilskudd.R @@ -101,6 +101,24 @@ test_that("errors for copy_Prodtilskudd", { options(width = unlist(linewidth)) }) +test_that("errors for copy_Prodtilskudd with extracted_date", { + + linewidth <- options("width") + options(width = 80) + + expect_error(copy_Prodtilskudd(from_path = tempdir(), to_path = "./", Pkode_year = "last", + Pkode_month = "10", extracted_date = "2023-03-31"), + regexp = "Contains only missing values. The input 'last' is", + fixed = TRUE) + + expect_error(copy_Prodtilskudd(from_path = tempdir(), to_path = "./", Pkode_year = 2020, + Pkode_month = "both", extracted_date = "2023-03-31"), + regexp = "The inputs 'both' and 'last' are not accepted when", + fixed = TRUE) + + options(width = unlist(linewidth)) +}) + test_that("errors for read_Prodtilskudd", { diff --git a/tests/testthat/test_add_produsent-deprecated.R b/tests/testthat/test_add_produsent-deprecated.R index 7a3c0e7..1ee3a58 100644 --- a/tests/testthat/test_add_produsent-deprecated.R +++ b/tests/testthat/test_add_produsent-deprecated.R @@ -20,12 +20,13 @@ test_that("Correct merging of produsent og produsent properties", { # Compare Add fylke, current fylkenr and current fylke with correct result - produsenter <- NVIdb::add_produsent(data = produsenter, - translation_table = prodnr_2_gjeldende_prodnr, - code_column = "prodnr8", - new_column = "gjeldende_prodnr8", - position = "left", - overwrite = FALSE) + produsenter <- expect_warning(add_produsent(data = produsenter, + translation_table = prodnr_2_gjeldende_prodnr, + code_column = "prodnr8", + new_column = "gjeldende_prodnr8", + position = "left", + overwrite = FALSE), + regexp = "'add_produsent' is replaced by 'add_produsent_properties'") expect_identical(produsenter, correct_result) # COORDINATES @@ -39,10 +40,11 @@ test_that("Correct merging of produsent og produsent properties", { ) colnames(correct_result) <- c("gjeldende_prodnr8", "prodnr8", "longitude", "latitude") - produsenter <- add_produsent(data = produsenter, - translation_table = prodnr_2_koordinater, - code_column = c("gjeldende_prodnr8" = "prodnr8"), - new_column = c("longitude" = "geo_eu89_o", "latitude" = "geo_eu89_n"), - position = "last") + produsenter <- expect_warning(add_produsent(data = produsenter, + translation_table = prodnr_2_koordinater, + code_column = c("gjeldende_prodnr8" = "prodnr8"), + new_column = c("longitude" = "geo_eu89_o", "latitude" = "geo_eu89_n"), + position = "last"), + regexp = "'add_produsent' is replaced by 'add_produsent_properties'") expect_identical(produsenter, correct_result) }) diff --git a/tests/testthat/test_login.R b/tests/testthat/test_login.R index 57d21ca..d07f88f 100644 --- a/tests/testthat/test_login.R +++ b/tests/testthat/test_login.R @@ -37,3 +37,23 @@ test_that("Errors or warnings for login", { options(width = unlist(linewidth)) }) + +test_that("Errors or warnings for login_EOS", { + linewidth <- options("width") + options(width = 80) + + expect_error(login_EOS(dbinterface = "noodbc"), + regexpr = "Variable 'dbinterface': Must be element of set") + + options(width = unlist(linewidth)) +}) + +test_that("Errors or warnings for login_PJS", { + linewidth <- options("width") + options(width = 80) + + expect_error(login_PJS(dbinterface = "noodbc"), + regexpr = "Variable 'dbinterface': Must be element of set") + + options(width = unlist(linewidth)) +}) diff --git a/tests/testthat/test_set_dir_NVI.R b/tests/testthat/test_set_dir_NVI.R index 4c9c824..78baf61 100644 --- a/tests/testthat/test_set_dir_NVI.R +++ b/tests/testthat/test_set_dir_NVI.R @@ -25,6 +25,19 @@ test_that("set_dir_NVI with input ignoring case", { }) +test_that("set_dir_NVI with slash = FALSE", { + # skip if no connection to 'FAG' have been established + skip_if_not(dir.exists(set_dir_NVI("FAG"))) + + expect_true(dir.exists(set_dir_NVI("LevReg", slash = FALSE))) + expect_true(dir.exists(set_dir_NVI("PRodtilskudd", slash = FALSE))) + expect_true(dir.exists(set_dir_NVI("prodregister", slash = FALSE))) + expect_true(dir.exists(set_dir_NVI("GrunnDataLand", slash = FALSE))) + expect_true(dir.exists(set_dir_NVI("Provedata_rapportering", slash = FALSE))) + expect_true(dir.exists(set_dir_NVI("OkProgrammer", slash = FALSE))) + +}) + test_that("set_dir_NVI using abbreviated input", { # skip if no connection to 'FAG' have been established skip_if_not(dir.exists(set_dir_NVI("FAG"))) @@ -47,5 +60,8 @@ test_that("set_dir_NVI error testing", { expect_error(set_dir_NVI("p"), regexp = "but is 'p'. Abbreviated arguments can only be matched to one single value among the possible arguments.$") + expect_error(set_dir_NVI("FAG", slash = "FALSE"), + regexp = "Variable 'slash': Must be of type 'logical flag'") + options(width = unlist(linewidth)) }) diff --git a/tests/testthat/test_set_disease_parameters.R b/tests/testthat/test_set_disease_parameters.R index 8786656..d3d47be 100644 --- a/tests/testthat/test_set_disease_parameters.R +++ b/tests/testthat/test_set_disease_parameters.R @@ -6,52 +6,65 @@ test_that("set disease parameters by direct input", { analytt2select = c("01220104%", "1502010235"), metode2select = c("070070", "070231", "010057", "060265")) expect_equal(parameters, - list("hensikt2select" = c("0100108018", "0100109003", "0100111003", "0800109"), + list("purpose" = NULL, + "hensikt2select" = c("0100108018", "0100109003", "0100111003", "0800109"), "hensikt2delete" = NULL, "utbrudd2select" = NULL, "metode2select" = c("070070", "070231", "010057", "060265"), "analytt2select" = c("01220104%", "1502010235"), "analytt2delete" = NULL, "art2select" = NULL, - "include_missing_art" = "never")) + "include_missing_art" = "never", + "FUN" = NULL, + "select_statement" = NULL)) parameters2 <- set_disease_parameters(selection_parameters = parameters) expect_equal(parameters2, - list("hensikt2select" = c("0100108018", "0100109003", "0100111003", "0800109"), + list("purpose" = NULL, + "hensikt2select" = c("0100108018", "0100109003", "0100111003", "0800109"), "hensikt2delete" = NULL, "utbrudd2select" = NULL, "metode2select" = c("070070", "070231", "010057", "060265"), "analytt2select" = c("01220104%", "1502010235"), "analytt2delete" = NULL, "art2select" = NULL, - "include_missing_art" = "never")) + "include_missing_art" = "never", + "FUN" = NULL, + "select_statement" = NULL)) parameters <- set_disease_parameters(hensikt2select = c("0100108018", "0100109003", "0100111003"), hensikt2delete = c("0800109"), utbrudd2select = "22", analytt2select = c("01220104%", "1502010235"), - metode2select = c("070070", "070231", "010057", "060265")) + metode2select = c("070070", "070231", "010057", "060265"), + art2select = c("03%", NA)) expect_equal(parameters, - list("hensikt2select" = c("0100108018", "0100109003", "0100111003"), + list("purpose" = NULL, + "hensikt2select" = c("0100108018", "0100109003", "0100111003"), "hensikt2delete" = c("0800109"), "utbrudd2select" = "22", "metode2select" = c("070070", "070231", "010057", "060265"), "analytt2select" = c("01220104%", "1502010235"), "analytt2delete" = NULL, - "art2select" = NULL, - "include_missing_art" = "never")) + "art2select" = c("03%", NA), + "include_missing_art" = "always", + "FUN" = NULL, + "select_statement" = NULL)) parameters2 <- set_disease_parameters(selection_parameters = parameters) expect_equal(parameters2, - list("hensikt2select" = c("0100108018", "0100109003", "0100111003"), + list("purpose" = NULL, + "hensikt2select" = c("0100108018", "0100109003", "0100111003"), "hensikt2delete" = c("0800109"), "utbrudd2select" = "22", "metode2select" = c("070070", "070231", "010057", "060265"), "analytt2select" = c("01220104%", "1502010235"), "analytt2delete" = NULL, - "art2select" = NULL, - "include_missing_art" = "never")) + "art2select" = c("03%", NA), + "include_missing_art" = "always", + "FUN" = NULL, + "select_statement" = NULL)) parameters <- set_disease_parameters(hensikt2select = c("0100108018", "0100109003", "0100111003"), hensikt2delete = c("0800109"), @@ -60,14 +73,39 @@ test_that("set disease parameters by direct input", { art2select = c("01%"), include_missing_art = "never") expect_equal(parameters, - list("hensikt2select" = c("0100108018", "0100109003", "0100111003"), + list("purpose" = NULL, + "hensikt2select" = c("0100108018", "0100109003", "0100111003"), + "hensikt2delete" = c("0800109"), + "utbrudd2select" = "22", + "metode2select" = NULL, + "analytt2select" = NULL, + "analytt2delete" = NULL, + "art2select" = c("01%"), + "include_missing_art" = "never", + "FUN" = NULL, + "select_statement" = NULL)) + + parameters <- expect_warning(set_disease_parameters(hensikt2select = c("0100108018", "0100109003", "0100111003"), + hensikt2delete = c("0800109"), + utbrudd2select = "22", + metode2select = NULL, + art2select = c("01%"), + missing_art = "non_selected_hensikt"), + regexp = "The argument 'missing_art' is deprecated.", + fixed = TRUE) + + expect_equal(parameters, + list("purpose" = NULL, + "hensikt2select" = c("0100108018", "0100109003", "0100111003"), "hensikt2delete" = c("0800109"), "utbrudd2select" = "22", "metode2select" = NULL, "analytt2select" = NULL, "analytt2delete" = NULL, "art2select" = c("01%"), - "include_missing_art" = "never")) + "include_missing_art" = "for_selected_hensikt", + "FUN" = NULL, + "select_statement" = NULL)) parameters <- set_disease_parameters(hensikt2select = c("0100108018", "0100109003", "0100111003"), hensikt2delete = c("0800109"), @@ -76,14 +114,17 @@ test_that("set disease parameters by direct input", { art2select = c("01%"), include_missing_art = NULL) expect_equal(parameters, - list("hensikt2select" = c("0100108018", "0100109003", "0100111003"), + list("purpose" = NULL, + "hensikt2select" = c("0100108018", "0100109003", "0100111003"), "hensikt2delete" = c("0800109"), "utbrudd2select" = "22", "metode2select" = NULL, "analytt2select" = NULL, "analytt2delete" = NULL, "art2select" = c("01%"), - "include_missing_art" = "never")) + "include_missing_art" = "never", + "FUN" = NULL, + "select_statement" = NULL)) parameters <- set_disease_parameters(hensikt2select = c("0100108018", "0100109003", "0100111003"), hensikt2delete = c("0800109"), @@ -92,25 +133,31 @@ test_that("set disease parameters by direct input", { art2select = c("01%", NA), include_missing_art = NULL) expect_equal(parameters, - list("hensikt2select" = c("0100108018", "0100109003", "0100111003"), + list("purpose" = NULL, + "hensikt2select" = c("0100108018", "0100109003", "0100111003"), "hensikt2delete" = c("0800109"), "utbrudd2select" = "22", "metode2select" = NULL, "analytt2select" = NULL, "analytt2delete" = NULL, "art2select" = c("01%", NA), - "include_missing_art" = "always")) + "include_missing_art" = "always", + "FUN" = NULL, + "select_statement" = NULL)) parameters2 <- set_disease_parameters(selection_parameters = parameters) expect_equal(parameters2, - list("hensikt2select" = c("0100108018", "0100109003", "0100111003"), + list("purpose" = NULL, + "hensikt2select" = c("0100108018", "0100109003", "0100111003"), "hensikt2delete" = c("0800109"), "utbrudd2select" = "22", "metode2select" = NULL, "analytt2select" = NULL, "analytt2delete" = NULL, "art2select" = c("01%", NA), - "include_missing_art" = "always")) + "include_missing_art" = "always", + "FUN" = NULL, + "select_statement" = NULL)) }) @@ -123,27 +170,34 @@ test_that("set disease parameters using parameter file", { con = file.path(tempdir(), "PD.R") ) - parameters <- set_disease_parameters(file = file.path(tempdir(), "PD.R")) + parameters <- expect_warning(set_disease_parameters(file = file.path(tempdir(), "PD.R")), + regexp = "The argument 'file' is deprecated") expect_equal(parameters, - list("hensikt2select" = c("0100108018", "0100109003", "0100111003", "0800109"), + list("purpose" = NULL, + "hensikt2select" = c("0100108018", "0100109003", "0100111003", "0800109"), "hensikt2delete" = NULL, "utbrudd2select" = NULL, "metode2select" = c("070070", "070231", "010057", "060265"), "analytt2select" = c("01220104%", "1502010235"), "analytt2delete" = NULL, "art2select" = NULL, - "include_missing_art" = "never")) + "include_missing_art" = "never", + "FUN" = NULL, + "select_statement" = NULL)) parameters <- set_disease_parameters(selection_parameters = file.path(tempdir(), "PD.R")) expect_equal(parameters, - list("hensikt2select" = c("0100108018", "0100109003", "0100111003", "0800109"), + list("purpose" = NULL, + "hensikt2select" = c("0100108018", "0100109003", "0100111003", "0800109"), "hensikt2delete" = NULL, "utbrudd2select" = NULL, "metode2select" = c("070070", "070231", "010057", "060265"), "analytt2select" = c("01220104%", "1502010235"), "analytt2delete" = NULL, "art2select" = NULL, - "include_missing_art" = "never")) + "include_missing_art" = "never", + "FUN" = NULL, + "select_statement" = NULL)) }) @@ -199,5 +253,44 @@ test_that("errors for set_disease_parameters", { include_missing_art = "yes"), regexp = "Variable 'include_missing_art': Must be element of set") + expect_error(set_disease_parameters(purpose = NA, + hensikt2delete = "0100108018", + analytt2select = "01220104%", + utbrudd2select = "2", + art2select = c("05%", NA), + include_missing_art = "always"), + regexp = "Variable 'purpose': May not be NA") + + expect_error(set_disease_parameters(purpose = 1, + hensikt2delete = "0100108018", + analytt2select = "01220104%", + utbrudd2select = "2", + art2select = c("05%", NA), + include_missing_art = "always"), + regexp = "Variable 'purpose': Must be of type 'string' (or 'NULL')", + fixed = TRUE) + + expect_error(set_disease_parameters(purpose = "ok_storfe_virus", + hensikt2delete = "0100108018", + analytt2select = "01220104%", + utbrudd2select = "2", + art2select = c("05%", NA), + include_missing_art = "always", + FUN = build_query_hensikt, + select_statement = 1), + regexp = "Must be of type 'string', * not 'double'", + fixed = TRUE) + + expect_error(set_disease_parameters(purpose = "ok_storfe_virus", + hensikt2delete = "0100108018", + analytt2select = "01220104%", + utbrudd2select = "2", + art2select = c("05%", NA), + include_missing_art = "always", + FUN = "build_query_hensikt", + select_statement = NULL), + regexp = "Must be a function (or 'NULL'), not 'character'", + fixed = TRUE) + options(width = unlist(linewidth)) }) diff --git a/vignettes/NVIdb.pdf b/vignettes/NVIdb.pdf index be18bed..dc7f02f 100644 Binary files a/vignettes/NVIdb.pdf and b/vignettes/NVIdb.pdf differ