diff --git a/.github/workflows/check-standard.yaml b/.github/workflows/check-standard.yaml index a3ac618..b6b055e 100644 --- a/.github/workflows/check-standard.yaml +++ b/.github/workflows/check-standard.yaml @@ -22,7 +22,7 @@ jobs: - {os: windows-latest, r: 'release'} - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} - {os: ubuntu-latest, r: 'release'} - - {os: ubuntu-latest, r: 'oldrel-1'} + # - {os: ubuntu-latest, r: 'oldrel-1'} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} diff --git a/R/combine_replicates.R b/R/combine_replicates.R index a8492f5..6a3c8a1 100644 --- a/R/combine_replicates.R +++ b/R/combine_replicates.R @@ -19,7 +19,8 @@ #' @examples #' local_dir <- system.file("extdata", "right", package = "verdata") #' replicates_data <- read_replicates(replicates_dir = local_dir, -#' violation = "reclutamiento", replicate_nums = c(1, 2), crash = TRUE) +#' violation = "reclutamiento", replicate_nums = c(1, 2), version = "v1", +#' crash = TRUE) #' replicates_obs_data <- summary_observed("reclutamiento", replicates_data, #' strata_vars = "sexo", conflict_filter = FALSE, forced_dis_filter = FALSE, #' edad_minors_filter = FALSE, include_props = FALSE) @@ -82,7 +83,8 @@ proportions_imputed <- function(complete_data, #' @examples #' \dontrun{ #' local_dir <- system.file("extdata", "right", package = "verdata") -#' replicates_data <- read_replicates(local_dir, "reclutamiento", c(1, 2)) +#' replicates_data <- read_replicates(local_dir, "reclutamiento", c(1, 2), +#' version = "v1") #' replicates_obs_data <- summary_observed("reclutamiento", replicates_data, #' strata_vars = "sexo", conflict_filter = FALSE, forced_dis_filter = FALSE, #' edad_minors_filter = FALSE, include_props = FALSE, digits = 2) diff --git a/R/confirm_files.R b/R/confirm_files.R index 88dcbdf..e4dc503 100644 --- a/R/confirm_files.R +++ b/R/confirm_files.R @@ -9,6 +9,10 @@ #' @param replicate_path Path to the replicate to be confirmed. The name #' of the files must include the violation in Spanish and lower case letters #' (homicidio, secuestro, reclutamiento, desaparicion). +#' @param version Version of the data being read in. Options are "v1" or "v2". +#' "v1" is appropriate for replicating the replicating the results of the joint +#' JEP-CEV-HRDAG project. "v2" is appropriate for conducting your new analyses +#' of the conflict in Colombia. # #' @return A data frame row with two columns: `replicate_path`, a string indicating the #' path to the replicate checked and `confirmed`, a boolean values indicating @@ -19,10 +23,16 @@ #' @examples #' local_dir_csv <- system.file("extdata", "right", #' "verdata-reclutamiento-R1.csv.zip", package = "verdata") -#' confirm_file(local_dir_csv) +#' confirm_file(local_dir_csv, version = "v1") #' #' @noRd -confirm_file <- function(replicate_path) { +confirm_file <- function(replicate_path, version) { + + if (is.null(version) | !version %in% c("v1", "v2")) { + + stop("Data version not properly specified. Options are 'v1' or 'v2'.") + + } violacion <- stringr::str_extract(pattern = "homicidio|desaparicion|secuestro|reclutamiento", replicate_path) @@ -37,19 +47,30 @@ confirm_file <- function(replicate_path) { algo = "sha1", file = TRUE))) - if (file_extension == "parquet") { + if (version == "v1" & file_extension == "parquet") { - file_test <- file %>% + file_test <- file_parquet_v1 %>% dplyr::filter(replica %in% hash_file$replica & violacion %in% hash_file$violacion) + } else if (version == "v2" & file_extension == "parquet") { - } else if (file_extension == "csv") { + file_test <- file_parquet_v2 %>% + dplyr::filter(replica %in% hash_file$replica & + violacion %in% hash_file$violacion) + + } else if (version == "v1" & file_extension == "csv") { - file_test <- file_csv %>% + file_test <- file_csv_v1 %>% dplyr::filter(replica %in% hash_file$replica & violacion %in% hash_file$violacion) + } else if (version == "v1" & file_extension == "csv") { + + file_test <- file_csv_v2 %>% + dplyr::filter(replica %in% hash_file$replica & + violacion %in% hash_file$violacion) # TODO: check + } is_eq <- all.equal(file_test, hash_file) @@ -64,10 +85,11 @@ confirm_file <- function(replicate_path) { else { - final <- medidas(replicate_path) - summary_table <- get(violacion) %>% + violacion_file <- paste0(violacion, "_", version) + + summary_table <- get(violacion_file) %>% dplyr::filter(replica %in% final$replica) final <- final[order(final$variable), ] @@ -106,6 +128,10 @@ confirm_file <- function(replicate_path) { #' "reclutamiento", and "desaparicion". #' @param replicate_nums A numeric vector containing the replicates to be analyzed. #' Values in the vector should be between 1 and 100 inclusive. +#' @param version Version of the data being read in. Options are "v1" or "v2". +#' "v1" is appropriate for replicating the replicating the results of the joint +#' JEP-CEV-HRDAG project. "v2" is appropriate for conducting your new analyses +#' of the conflict in Colombia. #' #' @return A data frame row with `replicate_num` rows and two columns: #' `replicate_path`, a string indicating the path to the replicate checked and @@ -117,17 +143,35 @@ confirm_file <- function(replicate_path) { #' #' @examples #' local_dir <- system.file("extdata", "right", package = "verdata") -#' confirm_files(local_dir, "reclutamiento", c(1, 2)) -confirm_files <- function(replicates_dir, violation, replicate_nums) { +#' confirm_files(local_dir, "reclutamiento", c(1, 2), version = "v1") +confirm_files <- function(replicates_dir, violation, replicate_nums, version) { files <- build_path(replicates_dir, violation, replicate_nums) - results <- purrr::map_dfr(files, confirm_file) + results <- purrr::map_dfr(files, confirm_file, version = version) if (any(!results$confirmed)) { warning("Some replicate file contents do not match the published versions") + } else if (version == "v1") { + + message("You are using v1 of the data. This version is appropriate for + replicating the results of the joint JEP-CEV-HRDAG project. If you + would like to conduct your own analysis of the conflict in Colombia, + please use v2 of the data.") + + } else if (version == "v2") { + + message("You are using v2 of the data. This version is appropriate for + conducting your own analysis of the conflict in Colombia. If you + would like to repliate the results of the joint JEP-CEV-HRDAG project, + please use v1 of the data.") + + } else if (is.null(version) | !version %in% c("v1", "v2")) { + + stop("Data version not properly specified. Options are 'v1' or 'v2'.") + } return(results) diff --git a/R/read_replicates.R b/R/read_replicates.R index 8f43a9f..1e3b903 100644 --- a/R/read_replicates.R +++ b/R/read_replicates.R @@ -9,6 +9,10 @@ #' @param replicate_path Path to the replicate. The name of the file must include #' the violation in Spanish and lower case letters (homicidio, secuestro, #' reclutamiento, desaparicion). +#' @param version Version of the data being read in. Options are "v1" or "v2". +#' "v1" is appropriate for replicating the replicating the results of the joint +#' JEP-CEV-HRDAG project. "v2" is appropriate for conducting your new analyses +#' of the conflict in Colombia. #' #' @return A data frame with the data from the indicated replicate and a column #' `match` indicating whether the file hash matches the expected hash. @@ -22,17 +26,24 @@ #' #' local_dir <- system.file("extdata", "right", #' package = "verdata", "verdata-reclutamiento-R1.parquet") -#' read_replicate(local_dir) +#' read_replicate(local_dir, version = "v1") #' #' @noRd -read_replicate <- function(replicate_path) { +read_replicate <- function(replicate_path, version) { + + if (is.null(version) | !version %in% c("v1", "v2")) { + + stop("Data version not properly specified. Options are 'v1' or 'v2'.") + + } violacion <- stringr::str_extract(pattern = "homicidio|desaparicion|secuestro|reclutamiento", replicate_path) file_extension <- stringr::str_extract(pattern = "parquet|csv", replicate_path) - if (file_extension == "parquet") { + + if (version == "v1" & file_extension == "parquet") { replicate_data <- arrow::read_parquet(replicate_path) @@ -41,11 +52,25 @@ read_replicate <- function(replicate_path) { replicate_path), hash = digest::digest(replicate_data, algo = "sha1")) - content_test <- content %>% + content_test <- content_parquet_v1 %>% dplyr::filter(replica %in% hash_intor$replica, violacion == hash_intor$violacion) - } else { + + } else if (version == "v2" & file_extension == "parquet") { + + replicate_data <- arrow::read_parquet(replicate_path) + + hash_intor <- dplyr::tibble(violacion = violacion, + replica = stringr::str_extract(pattern = ("(?:R)\\d+"), + replicate_path), + hash = digest::digest(replicate_data, algo = "sha1")) + + content_test <- content_parquet_v2 %>% + dplyr::filter(replica %in% hash_intor$replica, + violacion == hash_intor$violacion) + + } else if (version == "v1" & file_extension == "csv") { replicate_data <- readr::read_csv(replicate_path) @@ -54,7 +79,20 @@ read_replicate <- function(replicate_path) { replicate_path), hash = digest::digest(replicate_data, algo = "sha1")) - content_test <- content_csv %>% + content_test <- content_csv_v1 %>% + dplyr::filter(replica %in% hash_intor$replica) + + + } else if (version == "v2" & file_extension == "csv") { + + replicate_data <- readr::read_csv(replicate_path) + + hash_intor <- dplyr::tibble(violacion = violacion, + replica = stringr::str_extract(pattern = ("(?:R)\\d+"), + replicate_path), + hash = digest::digest(replicate_data, algo = "sha1")) + + content_test <- content_csv_v2 %>% dplyr::filter(replica %in% hash_intor$replica) } @@ -69,7 +107,9 @@ read_replicate <- function(replicate_path) { final <- medidas(replicate_path) - summary_table <- get(violacion) %>% + violacion_file <- paste0(violacion, "_", version) + + summary_table <- get(violacion_file) %>% dplyr::filter(replica %in% final$replica) final <- final[order(final$variable), ] @@ -102,6 +142,10 @@ read_replicate <- function(replicate_path) { #' "homicidio", "secuestro", "reclutamiento", and "desaparicion". #' @param replicate_nums A numeric vector containing the replicates to be analyzed. #' Values in the vector should be between 1 and 100 inclusive. +#' @param version Version of the data being read in. Options are "v1" or "v2". +#' "v1" is appropriate for replicating the replicating the results of the joint +#' JEP-CEV-HRDAG project. "v2" is appropriate for conducting your new analyses +#' of the conflict in Colombia. #' @param crash A parameter to define whether the function should crash if the #' content of the file is not identical to the one published. If crash = TRUE #' (default), it will return error and not read the data, if crash = FALSE, the @@ -114,12 +158,18 @@ read_replicate <- function(replicate_path) { #' #' @examples #' local_dir <- system.file("extdata", "right", package = "verdata") -#' read_replicates(local_dir, "reclutamiento", 1, 2) +#' read_replicates(local_dir, "reclutamiento", 1, 2, version = "v1") read_replicates <- function(replicates_dir, violation, replicate_nums, - crash = TRUE) { + version, crash = TRUE) { + + if (is.null(version) | !version %in% c("v1", "v2")) { + + stop("Data version not properly specified. Options are 'v1' or 'v2'.") + + } files <- build_path(replicates_dir, violation, replicate_nums) - replicate_data <- purrr::map_dfr(files, read_replicate) + replicate_data <- purrr::map_dfr(files, read_replicate, version = version) corrupted_replicates <- replicate_data %>% dplyr::filter(!match) %>% @@ -130,6 +180,22 @@ read_replicates <- function(replicates_dir, violation, replicate_nums, if (all(replicate_data$match)) { + if (version == "v1") { + + message("You are using v1 of the data. This version is appropriate for + replicating the results of the joint JEP-CEV-HRDAG project. If you + would like to conduct your own analysis of the conflict in Colombia, + please use v2 of the data.") + + } else if (version == "v2") { + + message("You are using v2 of the data. This version is appropriate for + conducting your own analysis of the conflict in Colombia. If you + would like to repliate the results of the joint JEP-CEV-HRDAG project, + please use v1 of the data.") + + } + return(replicate_data %>% dplyr::select(-match)) } else { @@ -141,6 +207,23 @@ read_replicates <- function(replicates_dir, violation, replicate_nums, } else { warning(glue::glue("The content of the files is not identical to the ones published.\nThe results of the analysis may be inconsistent.\nThe following replicates have incorrect content:\n{paste0(corrupted_replicates, collapse = '\n')}")) + + if (version == "v1") { + + message("You are using v1 of the data. This version is appropriate for + replicating the results of the joint JEP-CEV-HRDAG project. If you + would like to conduct your own analysis of the conflict in Colombia, + please use v2 of the data.") + + } else if (version == "v2") { + + message("You are using v2 of the data. This version is appropriate for + conducting your own analysis of the conflict in Colombia. If you + would like to repliate the results of the joint JEP-CEV-HRDAG project, + please use v1 of the data.") + + } + return(replicate_data %>% dplyr::select(-match)) } diff --git a/R/summary_observed.R b/R/summary_observed.R index a4efc46..5248e2e 100644 --- a/R/summary_observed.R +++ b/R/summary_observed.R @@ -18,7 +18,7 @@ #' @examples #' \dontrun{ #' local_dir <- system.file("extdata", "right", package = "verdata") -#' replicates_data <- read_replicates(local_dir, "reclutamiento", c(1, 2)) +#' replicates_data <- read_replicates(local_dir, "reclutamiento", c(1, 2), version = "v1") #' tab_observed <- summary_observed("reclutamiento", replicates_data, #' strata_vars = "sexo", conflict_filter = TRUE, forced_dis_filter = FALSE, #' edad_minors_filter = TRUE, include_props = TRUE) @@ -76,7 +76,7 @@ proportions_observed <- function(obs_data, #' #' @examples #' local_dir <- system.file("extdata", "right", package = "verdata") -#' replicates_data <- read_replicates(local_dir, "reclutamiento", c(1, 2)) +#' replicates_data <- read_replicates(local_dir, "reclutamiento", c(1, 2), version = "v1") #' tab_observed <- summary_observed("reclutamiento", replicates_data, #' strata_vars = "sexo", conflict_filter = FALSE, forced_dis_filter = FALSE, #' edad_minors_filter = FALSE, include_props = FALSE, digits = 2) diff --git a/R/sysdata.rda b/R/sysdata.rda index e6a4855..64338e4 100644 Binary files a/R/sysdata.rda and b/R/sysdata.rda differ diff --git a/inst/extdata/corrected-right/verdata-corrected-reclutamiento-R1.csv.zip b/inst/extdata/corrected-right/verdata-corrected-reclutamiento-R1.csv.zip deleted file mode 100644 index 5b61e72..0000000 Binary files a/inst/extdata/corrected-right/verdata-corrected-reclutamiento-R1.csv.zip and /dev/null differ diff --git a/inst/extdata/corrected-right/verdata-corrected-reclutamiento-R1.parquet b/inst/extdata/corrected-right/verdata-corrected-reclutamiento-R1.parquet deleted file mode 100644 index b726eeb..0000000 Binary files a/inst/extdata/corrected-right/verdata-corrected-reclutamiento-R1.parquet and /dev/null differ diff --git a/inst/extdata/corrected-right/verdata-corrected-reclutamiento-R2.parquet b/inst/extdata/corrected-right/verdata-corrected-reclutamiento-R2.parquet deleted file mode 100644 index e5326d4..0000000 Binary files a/inst/extdata/corrected-right/verdata-corrected-reclutamiento-R2.parquet and /dev/null differ diff --git a/man/combine_replicates.Rd b/man/combine_replicates.Rd index 53f5a9d..2fde450 100644 --- a/man/combine_replicates.Rd +++ b/man/combine_replicates.Rd @@ -52,7 +52,8 @@ Combine replicates according to the Normal approximation using the laws of total \examples{ \dontrun{ local_dir <- system.file("extdata", "right", package = "verdata") -replicates_data <- read_replicates(local_dir, "reclutamiento", c(1, 2)) +replicates_data <- read_replicates(local_dir, "reclutamiento", c(1, 2), +version = "v1") replicates_obs_data <- summary_observed("reclutamiento", replicates_data, strata_vars = "sexo", conflict_filter = FALSE, forced_dis_filter = FALSE, edad_minors_filter = FALSE, include_props = FALSE, digits = 2) diff --git a/man/confirm_files.Rd b/man/confirm_files.Rd index f7cabda..5c27aae 100644 --- a/man/confirm_files.Rd +++ b/man/confirm_files.Rd @@ -4,7 +4,7 @@ \alias{confirm_files} \title{Confirm files are identical to the ones published.} \usage{ -confirm_files(replicates_dir, violation, replicate_nums) +confirm_files(replicates_dir, violation, replicate_nums, version) } \arguments{ \item{replicates_dir}{Directory containing the replicates. @@ -16,6 +16,11 @@ letters (homicidio, secuestro, reclutamiento, desaparicion).} \item{replicate_nums}{A numeric vector containing the replicates to be analyzed. Values in the vector should be between 1 and 100 inclusive.} + +\item{version}{Version of the data being read in. Options are "v1" or "v2". +"v1" is appropriate for replicating the replicating the results of the joint +JEP-CEV-HRDAG project. "v2" is appropriate for conducting your new analyses +of the conflict in Colombia.} } \value{ A data frame row with \code{replicate_num} rows and two columns: @@ -28,5 +33,5 @@ Confirm files are identical to the ones published. } \examples{ local_dir <- system.file("extdata", "right", package = "verdata") -confirm_files(local_dir, "reclutamiento", c(1, 2)) +confirm_files(local_dir, "reclutamiento", c(1, 2), version = "v1") } diff --git a/man/proportions_imputed.Rd b/man/proportions_imputed.Rd index 54a91d0..b6c4cac 100644 --- a/man/proportions_imputed.Rd +++ b/man/proportions_imputed.Rd @@ -27,7 +27,8 @@ applying \code{combine_replicates} to complete data (includes imputed values). \examples{ local_dir <- system.file("extdata", "right", package = "verdata") replicates_data <- read_replicates(replicates_dir = local_dir, -violation = "reclutamiento", replicate_nums = c(1, 2), crash = TRUE) +violation = "reclutamiento", replicate_nums = c(1, 2), version = "v1", +crash = TRUE) replicates_obs_data <- summary_observed("reclutamiento", replicates_data, strata_vars = "sexo", conflict_filter = FALSE, forced_dis_filter = FALSE, edad_minors_filter = FALSE, include_props = FALSE) diff --git a/man/proportions_observed.Rd b/man/proportions_observed.Rd index d16d3e1..8c99c99 100644 --- a/man/proportions_observed.Rd +++ b/man/proportions_observed.Rd @@ -26,7 +26,7 @@ Calculate the proportions of each level of a variable after applying \examples{ \dontrun{ local_dir <- system.file("extdata", "right", package = "verdata") -replicates_data <- read_replicates(local_dir, "reclutamiento", c(1, 2)) +replicates_data <- read_replicates(local_dir, "reclutamiento", c(1, 2), version = "v1") tab_observed <- summary_observed("reclutamiento", replicates_data, strata_vars = "sexo", conflict_filter = TRUE, forced_dis_filter = FALSE, edad_minors_filter = TRUE, include_props = TRUE) diff --git a/man/read_replicates.Rd b/man/read_replicates.Rd index 55be8f4..d6e8c9c 100644 --- a/man/read_replicates.Rd +++ b/man/read_replicates.Rd @@ -4,7 +4,13 @@ \alias{read_replicates} \title{Read replicates in a directory and verify they are identical to the ones published.} \usage{ -read_replicates(replicates_dir, violation, replicate_nums, crash = TRUE) +read_replicates( + replicates_dir, + violation, + replicate_nums, + version, + crash = TRUE +) } \arguments{ \item{replicates_dir}{A path to the directory containing the replicates. @@ -18,6 +24,11 @@ and the replicate number preceded by "R", (e.g., "R1" for replicate 1).} \item{replicate_nums}{A numeric vector containing the replicates to be analyzed. Values in the vector should be between 1 and 100 inclusive.} +\item{version}{Version of the data being read in. Options are "v1" or "v2". +"v1" is appropriate for replicating the replicating the results of the joint +JEP-CEV-HRDAG project. "v2" is appropriate for conducting your new analyses +of the conflict in Colombia.} + \item{crash}{A parameter to define whether the function should crash if the content of the file is not identical to the one published. If crash = TRUE (default), it will return error and not read the data, if crash = FALSE, the @@ -31,5 +42,5 @@ Read replicates in a directory and verify they are identical to the ones publish } \examples{ local_dir <- system.file("extdata", "right", package = "verdata") -read_replicates(local_dir, "reclutamiento", 1, 2) +read_replicates(local_dir, "reclutamiento", 1, 2, version = "v1") } diff --git a/man/summary_observed.Rd b/man/summary_observed.Rd index 5da1817..b16563a 100644 --- a/man/summary_observed.Rd +++ b/man/summary_observed.Rd @@ -46,7 +46,7 @@ Summary statistics for observed data. } \examples{ local_dir <- system.file("extdata", "right", package = "verdata") -replicates_data <- read_replicates(local_dir, "reclutamiento", c(1, 2)) +replicates_data <- read_replicates(local_dir, "reclutamiento", c(1, 2), version = "v1") tab_observed <- summary_observed("reclutamiento", replicates_data, strata_vars = "sexo", conflict_filter = FALSE, forced_dis_filter = FALSE, edad_minors_filter = FALSE, include_props = FALSE, digits = 2) diff --git a/tests/testthat/test-combine_replicates.R b/tests/testthat/test-combine_replicates.R index ebb097b..cae876a 100644 --- a/tests/testthat/test-combine_replicates.R +++ b/tests/testthat/test-combine_replicates.R @@ -6,7 +6,7 @@ local_dir <- system.file("extdata", "right", package = "verdata") -replicates_data <- read_replicates(local_dir, "reclutamiento", c(1, 2)) +replicates_data <- read_replicates(local_dir, "reclutamiento", c(1, 2), version = "v1") replicates_data_filter <- filter_standard_cev(replicates_data, "reclutamiento", diff --git a/tests/testthat/test-confirm_files.R b/tests/testthat/test-confirm_files.R index 7fcf315..0a4c189 100644 --- a/tests/testthat/test-confirm_files.R +++ b/tests/testthat/test-confirm_files.R @@ -10,19 +10,19 @@ csv_right <- system.file("extdata", "right", package = "verdata", "verdata-reclu testthat::test_that("Hashing file", { - testthat::expect_true(confirm_file(right_dir)$confirmed) + testthat::expect_true(confirm_file(right_dir, version = "v1")$confirmed) }) testthat::test_that("Hashing wrong file", { - testthat::expect_false(confirm_file(wrong_dir)$confirmed) + testthat::expect_false(confirm_file(wrong_dir, version = "v1")$confirmed) }) testthat::test_that("Hashing right csv file", { - testthat::expect_true(confirm_file(csv_right)$confirmed) + testthat::expect_true(confirm_file(csv_right, version = "v1")$confirmed) }) @@ -31,55 +31,55 @@ wrong_dir <- system.file("extdata", "wrong", package = "verdata") testthat::test_that("Hashing files", { - testthat::expect_true(all(confirm_files(right_dir, "reclutamiento", c(1, 2))$confirmed)) + testthat::expect_true(all(confirm_files(right_dir, "reclutamiento", c(1, 2), version = "v1")$confirmed)) }) testthat::test_that("Hashing wrong files", { - testthat::expect_false(all(confirm_files(wrong_dir, "reclutamiento", c(1, 2))$confirmed)) + testthat::expect_false(all(confirm_files(wrong_dir, "reclutamiento", c(1, 2), version = "v1")$confirmed)) }) testthat::test_that("Function should return an error if the violation type is incorrect", { - testthat::expect_error(confirm_files(right_dir, "RECLUTAMIENTO", c(1, 2))) + testthat::expect_error(confirm_files(right_dir, "RECLUTAMIENTO", c(1, 2), version = "v1")) }) testthat::test_that("Expect message when number of replicates exceed available replicates", { - testthat::expect_error(confirm_files(right_dir, "reclutamiento", 90:110)) + testthat::expect_error(confirm_files(right_dir, "reclutamiento", 90:110, version = "v1")) }) testthat::test_that("Expect message when first replicate is less than 1", { - testthat::expect_error(confirm_files(right_dir, "reclutamiento", 0:2)) + testthat::expect_error(confirm_files(right_dir, "reclutamiento", 0:2, version = "v1")) }) testthat::test_that("Expect message when first replicate is less than 1 and last is more than 100", { - testthat::expect_error(confirm_files(right_dir, "reclutamiento", 0:101)) + testthat::expect_error(confirm_files(right_dir, "reclutamiento", 0:101, version = "v1")) }) testthat::test_that("Function should return an error if replicate numbers are misspecified", { - testthat::expect_error(confirm_files(right_dir, "reclutamiento", c("1", 2))) + testthat::expect_error(confirm_files(right_dir, "reclutamiento", c("1", 2), version = "v1")) }) testthat::test_that("Function should return an error if replicate numbers are misspecified", { - testthat::expect_error(confirm_files(right_dir, "RECLUTAMIENTO", c(1, "dos"))) + testthat::expect_error(confirm_files(right_dir, "RECLUTAMIENTO", c(1, "dos"), version = "v1")) }) testthat::test_that("Function should return an error if one or more of the replicates is not in the directory, but within the plausible bounds", { - testthat::expect_error(confirm_files(right_dir, "reclutamiento", 1:10)) + testthat::expect_error(confirm_files(right_dir, "reclutamiento", 1:10, version = "v1")) }) diff --git a/tests/testthat/test-estimate_mse.R b/tests/testthat/test-estimate_mse.R index 60604cf..7afbfbb 100644 --- a/tests/testthat/test-estimate_mse.R +++ b/tests/testthat/test-estimate_mse.R @@ -97,7 +97,8 @@ testthat::test_that("mse function returns correct results for estimable and non- testthat::test_that("mse function returns correct results when using lookup functionality", { local_dir <- system.file("extdata", "right", package = "verdata") - replicates <- read_replicates(local_dir, "reclutamiento", 1, 1) + replicates <- read_replicates(local_dir, "reclutamiento", replicate_nums = 1, + version = "v1", crash = 1) estimates_dir <- system.file("extdata", "estimates", package = "verdata") @@ -143,7 +144,8 @@ testthat::test_that("mse function returns correct results when using lookup func testthat::test_that("mse function returns errors when inputs are misspecified", { local_dir <- system.file("extdata", "right", package = "verdata") - replicates <- read_replicates(local_dir, "reclutamiento", 1, 1) + replicates <- read_replicates(local_dir, "reclutamiento", replicate_nums = 1, + version = "v1", crash = 1) stratum_5 <- replicates %>% dplyr::select(-tidyselect::starts_with("in_")) @@ -167,7 +169,8 @@ testthat::test_that("lookup function correctly finds strata that have and have n local_dir <- system.file("extdata", "right", package = "verdata") - replicates <- read_replicates(local_dir, "reclutamiento", 1, 1) + replicates <- read_replicates(local_dir, "reclutamiento", replicate_nums = 1, + version = "v1", crash = 1) estimates_dir <- system.file("extdata", "estimates", package = "verdata") diff --git a/tests/testthat/test-filter_standard_cev.R b/tests/testthat/test-filter_standard_cev.R index 79ef743..4a7c3b7 100644 --- a/tests/testthat/test-filter_standard_cev.R +++ b/tests/testthat/test-filter_standard_cev.R @@ -6,7 +6,7 @@ local_dir <- system.file("extdata", "right", package = "verdata") -replicates_data <- read_replicates(local_dir, "reclutamiento", c(1, 2)) +replicates_data <- read_replicates(local_dir, "reclutamiento", c(1, 2), version = "v1") expected <- verdata::filter_standard_cev(replicates_data, "reclutamiento", @@ -118,8 +118,8 @@ testthat::test_that("The variables is_forced_dis and is_conflict are type "desaparicion", perp_change = TRUE) - testthat::expect_is(data_dis$is_forced_dis, "integer") - testthat::expect_is(data_dis$is_conflict, "integer") + testthat::expect_type(data_dis$is_forced_dis, "integer") + testthat::expect_type(data_dis$is_conflict, "integer") }) diff --git a/tests/testthat/test-lookup_estimates.R b/tests/testthat/test-lookup_estimates.R index 31739f5..4b7e6ad 100644 --- a/tests/testthat/test-lookup_estimates.R +++ b/tests/testthat/test-lookup_estimates.R @@ -5,7 +5,8 @@ # ============================================ local_dir <- system.file("extdata", "right", package = "verdata") -replicates <- read_replicates(local_dir, "reclutamiento", 1, 1) +replicates <- read_replicates(local_dir, "reclutamiento", replicate_nums = 1, + version = "v1", crash = 1) estimates_dir <- system.file("extdata", "estimates", package = "verdata") diff --git a/tests/testthat/test-read_replicates.R b/tests/testthat/test-read_replicates.R index cb8d268..e32aa67 100644 --- a/tests/testthat/test-read_replicates.R +++ b/tests/testthat/test-read_replicates.R @@ -10,22 +10,22 @@ csv_right <- system.file("extdata", "right", package = "verdata", "verdata-reclu testthat::test_that("Hashing content", { - testthat::expect_true(all(read_replicate(right_dir)$match)) - testthat::expect_s3_class(read_replicate(right_dir), "data.frame") + testthat::expect_true(all(read_replicate(right_dir, version = "v1")$match)) + testthat::expect_s3_class(read_replicate(right_dir, version = "v1"), "data.frame") }) testthat::test_that("Hashing csv content", { - testthat::expect_s3_class(read_replicate(csv_right), "data.frame") - testthat::expect_true(all(read_replicate(csv_right)$match)) + testthat::expect_s3_class(read_replicate(csv_right, version = "v1"), "data.frame") + testthat::expect_true(all(read_replicate(csv_right, version = "v1")$match)) }) testthat::test_that("Hashing wrong content with default crash", { - testthat::expect_s3_class(read_replicate(wrong_dir), "data.frame") - testthat::expect_false(all(read_replicate(wrong_dir)$match)) + testthat::expect_s3_class(read_replicate(wrong_dir, version = "v1"), "data.frame") + testthat::expect_false(all(read_replicate(wrong_dir, version = "v1")$match)) }) @@ -34,60 +34,60 @@ wrong_dir <- system.file("extdata", "wrong", package = "verdata") testthat::test_that("Hashing content of files", { - testthat::expect_s3_class(read_replicates(right_dir, "reclutamiento", c(1, 2)), "data.frame") + testthat::expect_s3_class(read_replicates(right_dir, "reclutamiento", c(1, 2), version = "v1"), "data.frame") }) testthat::test_that("Hashing content of wrong files with default crash", { - testthat::expect_error(read_replicates(wrong_dir, "reclutamiento", c(1, 2))) + testthat::expect_error(read_replicates(wrong_dir, "reclutamiento", c(1, 2), version = "v1")) }) testthat::test_that("Hashing content of wrong with crash set to F", { - testthat::expect_warning(read_replicates(wrong_dir, "reclutamiento", c(1, 2), FALSE)) - testthat::expect_s3_class(read_replicates(wrong_dir, "reclutamiento", c(1, 2), FALSE), "data.frame") + testthat::expect_warning(read_replicates(wrong_dir, "reclutamiento", c(1, 2), version = "v1", FALSE)) + testthat::expect_s3_class(read_replicates(wrong_dir, "reclutamiento", c(1, 2), version = "v1", FALSE), "data.frame") }) testthat::test_that("Function should return an error if the violation type is incorrect", { - testthat::expect_error(read_replicates(right_dir, "desplazamiento", c(1, 2))) + testthat::expect_error(read_replicates(right_dir, "desplazamiento", c(1, 2), version = "v1")) }) testthat::test_that("Expect message when number of replicates exceed available replicates", { - testthat::expect_error(read_replicates(right_dir, "reclutamiento", 90:110)) + testthat::expect_error(read_replicates(right_dir, "reclutamiento", 90:110, version = "v1")) }) testthat::test_that("Expect message when first replicate is less than 1", { - testthat::expect_error(read_replicates(right_dir, "reclutamiento", 0:2)) + testthat::expect_error(read_replicates(right_dir, "reclutamiento", 0:2, version = "v1")) }) testthat::test_that("Expect message when first replicate is less than 1 and last is more than 100", { - testthat::expect_error(read_replicates(right_dir, "reclutamiento", 0:101)) + testthat::expect_error(read_replicates(right_dir, "reclutamiento", 0:101, version = "v1")) }) testthat::test_that("Function should return an error if replicate numbers are misspecified", { - testthat::expect_error(read_replicates(right_dir, "reclutamiento", c("1", 2))) + testthat::expect_error(read_replicates(right_dir, "reclutamiento", c("1", 2), version = "v1")) }) testthat::test_that("Function should return an error if replicate numbers are misspecified", { - testthat::expect_error(read_replicates(right_dir, "RECLUTAMIENTO", c(1, "dos"))) + testthat::expect_error(read_replicates(right_dir, "RECLUTAMIENTO", c(1, "dos"), version = "v1")) }) testthat::test_that("Function should return an error if one or more of the replicates is not in the directory, but within the plausible bounds", { - testthat::expect_error(read_replicates(right_dir, "reclutamiento", 1:10)) + testthat::expect_error(read_replicates(right_dir, "reclutamiento", 1:10, version = "v1")) }) diff --git a/tests/testthat/test-summary-observed.R b/tests/testthat/test-summary-observed.R index 662006c..9e101e2 100644 --- a/tests/testthat/test-summary-observed.R +++ b/tests/testthat/test-summary-observed.R @@ -6,7 +6,7 @@ # local_dir <- system.file("extdata", "right", package = "verdata") -replicates_data <- read_replicates(local_dir, "reclutamiento", c(1, 2)) +replicates_data <- read_replicates(local_dir, "reclutamiento", c(1, 2), version = "v1") replicates_data_filter <- filter_standard_cev(replicates_data, "reclutamiento",