From d7d049d05fcbb38f7fa44ee0d35c497f22468a92 Mon Sep 17 00:00:00 2001 From: Maria Gargiulo Date: Wed, 16 Aug 2023 17:22:49 +0100 Subject: [PATCH] all existing checks pass --- R/read_replicates.R | 10 +++--- tests/testthat/test-combine_replicates.R | 2 +- tests/testthat/test-confirm_files.R | 25 +++++++-------- tests/testthat/test-filter_standard_cev.R | 2 +- tests/testthat/test-read_replicates.R | 37 +++++++++-------------- tests/testthat/test-summary-observed.R | 2 +- 6 files changed, 32 insertions(+), 46 deletions(-) diff --git a/R/read_replicates.R b/R/read_replicates.R index 358b2e5..c57e655 100644 --- a/R/read_replicates.R +++ b/R/read_replicates.R @@ -9,11 +9,9 @@ #' @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 crash A parameter to define whether the function should crash if the file -#' is not identical to the one published. If crash = TRUE (default), the data won't -#' be loaded. If crash = FALSE, the data will be loaded with a warning. #' -#' @return A data frame with the data from the indicated replicate. +#' @return A data frame with the data from the indicated replicate and a column +#' `match` indicating whether the file hash matches the expected hash. #' #' @importFrom dplyr %>% #' @@ -27,7 +25,7 @@ #' read_replicate(local_dir) #' #' @noRd -read_replicate <- function(replicate_path, crash = TRUE) { +read_replicate <- function(replicate_path) { violacion <- stringr::str_extract(pattern = "homicidio|desaparicion|secuestro|reclutamiento", replicate_path) @@ -121,7 +119,7 @@ read_replicates <- function(replicates_dir, violation, replicate_nums, crash = TRUE) { files <- build_path(replicates_dir, violation, replicate_nums) - replicate_data <- purrr::map_dfr(files, read_replicate, crash) + replicate_data <- purrr::map_dfr(files, read_replicate) corrupted_replicates <- replicate_data %>% dplyr::filter(!match) %>% diff --git a/tests/testthat/test-combine_replicates.R b/tests/testthat/test-combine_replicates.R index 5ddb629..52dafda 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", 1, 2) +replicates_data <- read_replicates(local_dir, "reclutamiento", c(1, 2)) 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 b38cbbc..f660e40 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_message(confirm_file(right_dir), "You have the right file!") + testthat::expect_true(confirm_file(right_dir)$confirmed) }) testthat::test_that("Hashing wrong file", { - testthat::expect_error(confirm_file(wrong_dir)) + testthat::expect_false(confirm_file(wrong_dir)$confirmed) }) testthat::test_that("Hashing right csv file", { - testthat::expect_message(confirm_file(csv_right), "You have the right file!") + testthat::expect_true(confirm_file(csv_right)$confirmed) }) @@ -31,52 +31,49 @@ wrong_dir <- system.file("extdata", "wrong", package = "verdata") testthat::test_that("Hashing files", { - testthat::expect_message(confirm_files(right_dir, "reclutamiento", 1, 2), "You have the right file!") + testthat::expect_true(all(confirm_files(right_dir, "reclutamiento", c(1, 2))$confirmed)) }) testthat::test_that("Hashing wrong files", { - testthat::expect_error(confirm_files(wrong_dir, "reclutamiento", 1, 2)) + testthat::expect_false(all(confirm_files(wrong_dir, "reclutamiento", c(1, 2))$confirmed)) }) testthat::test_that("Function should return an error if the violation type is incorrect", { - testthat::expect_error(confirm_files(right_dir, "RECLUTAMIENTO", 1, 2)) + testthat::expect_error(confirm_files(right_dir, "RECLUTAMIENTO", c(1, 2))) }) testthat::test_that("Expect message when number of replicates exceed available replicates", { - testthat::expect_message(confirm_files(right_dir, "reclutamiento", 90, 110), - "There are only 100 replicates available. Authenticated replicates 90 to 100") + testthat::expect_error(confirm_files(right_dir, "reclutamiento", 90:110)) }) testthat::test_that("Expect message when first replicate is less than 1", { - testthat::expect_message(confirm_files(right_dir, "reclutamiento", 0, 2), - "First replicate available is replicate 1. Authenticated replicates 1 to 2") + testthat::expect_error(confirm_files(right_dir, "reclutamiento", 0:2)) }) testthat::test_that("Expect message when first replicate is less than 1 and last is more than 100", { - testthat::expect_message(confirm_files(right_dir, "reclutamiento", 0, 101), - "Replicates available go from 1 to 100. Authenticated replicates 1 to 100") + testthat::expect_error(confirm_files(right_dir, "reclutamiento", 0:101)) }) testthat::test_that("Function should return an error if the first_rep argument dos not have the correct format", { - testthat::expect_error(confirm_files(right_dir, "reclutamiento", "1", 2)) + testthat::expect_error(confirm_files(right_dir, "reclutamiento", c("1", 2))) }) testthat::test_that("Function should return an error if the last_rep argument dos not have the correct format", { - testthat::expect_error(confirm_files(right_dir, "RECLUTAMIENTO", 1, "dos")) + testthat::expect_error(confirm_files(right_dir, "RECLUTAMIENTO", c(1, "dos"))) }) diff --git a/tests/testthat/test-filter_standard_cev.R b/tests/testthat/test-filter_standard_cev.R index 1124d4d..d9c0754 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", 1, 2) +replicates_data <- read_replicates(local_dir, "reclutamiento", c(1, 2)) expected <- filter_standard_cev(replicates_data, "reclutamiento", diff --git a/tests/testthat/test-read_replicates.R b/tests/testthat/test-read_replicates.R index 3e39d2e..da8f2ea 100644 --- a/tests/testthat/test-read_replicates.R +++ b/tests/testthat/test-read_replicates.R @@ -10,6 +10,7 @@ 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") }) @@ -17,21 +18,14 @@ testthat::test_that("Hashing content", { 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::test_that("Hashing wrong content with default crash", { - testthat::expect_error(read_replicate(wrong_dir)) - -}) - -testthat::test_that("Hashing wrong content with crash set to F", { - - testthat::expect_s3_class(read_replicate(wrong_dir, FALSE), - "data.frame") - testthat::expect_warning(read_replicate(wrong_dir, FALSE), "The content of the files is not identical to the ones published. - The results of the analysis may be inconsistent.") + testthat::expect_s3_class(read_replicate(wrong_dir), "data.frame") + testthat::expect_false(all(read_replicate(wrong_dir)$match)) }) @@ -40,57 +34,54 @@ wrong_dir <- system.file("extdata", "wrong", package = "verdata") testthat::test_that("Hashing content of files", { - testthat::expect_s3_class(read_replicates(right_dir, "reclutamiento", 1, 2), "data.frame") + testthat::expect_s3_class(read_replicates(right_dir, "reclutamiento", c(1, 2)), "data.frame") }) testthat::test_that("Hashing content of wrong files with default crash", { - testthat::expect_error(read_replicates(wrong_dir, "reclutamiento", 1, 2)) + testthat::expect_error(read_replicates(wrong_dir, "reclutamiento", c(1, 2))) }) testthat::test_that("Hashing content of wrong with crash set to F", { - testthat::expect_warning(read_replicates(wrong_dir, "reclutamiento", 1, 2, FALSE)) - testthat::expect_s3_class(read_replicates(wrong_dir, "reclutamiento", 1, 2, FALSE), "data.frame") + 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::test_that("Function should return an error if the violation type is incorrect", { - testthat::expect_error(read_replicates(right_dir, "desplazamiento", 1, 2)) + testthat::expect_error(read_replicates(right_dir, "desplazamiento", c(1, 2))) }) testthat::test_that("Expect message when number of replicates exceed available replicates", { - testthat::expect_message(read_replicates(right_dir, "reclutamiento", 90, 110), - "There are only 100 replicates available. Authenticated and loaded replicates 90 to 100") + testthat::expect_error(read_replicates(right_dir, "reclutamiento", 90:110)) }) testthat::test_that("Expect message when first replicate is less than 1", { - testthat::expect_message(read_replicates(right_dir, "reclutamiento", 0, 2), - "First replicate available is replicate 1. Authenticated and loaded replicates 1 to 2") + testthat::expect_error(read_replicates(right_dir, "reclutamiento", 0:2)) }) testthat::test_that("Expect message when first replicate is less than 1 and last is more than 100", { - testthat::expect_message(read_replicates(right_dir, "reclutamiento", 0, 101), - "Replicates available go from 1 to 100. Authenticated and loaded replicates 1 to 100") + testthat::expect_error(read_replicates(right_dir, "reclutamiento", 0:101)) }) testthat::test_that("Function should return an error if the first_rep argument dos not have the correct format", { - testthat::expect_error(read_replicates(right_dir, "reclutamiento", "1", 2)) + testthat::expect_error(read_replicates(right_dir, "reclutamiento", c("1", 2))) }) testthat::test_that("Function should return an error if the last_rep argument dos not have the correct format", { - testthat::expect_error(read_replicates(right_dir, "RECLUTAMIENTO", 1, "dos")) + testthat::expect_error(read_replicates(right_dir, "RECLUTAMIENTO", c(1, "dos"))) }) diff --git a/tests/testthat/test-summary-observed.R b/tests/testthat/test-summary-observed.R index df553a4..b62308f 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", 1, 2) +replicates_data <- read_replicates(local_dir, "reclutamiento", c(1, 2)) replicates_data_filter <- filter_standard_cev(replicates_data, "reclutamiento",