From b83959eb1d6ab22c83db450bd3a3a7aabd09bd68 Mon Sep 17 00:00:00 2001 From: Maria Gargiulo Date: Thu, 12 Sep 2024 15:12:08 +0100 Subject: [PATCH] finalize version argument --- R/confirm_files.R | 19 +++++++++++++++++-- R/read_replicates.R | 21 +++++++++++++++++++-- man/confirm_files.Rd | 6 ++++-- man/read_replicates.Rd | 6 ++++-- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/R/confirm_files.R b/R/confirm_files.R index a6775c9..e4dc503 100644 --- a/R/confirm_files.R +++ b/R/confirm_files.R @@ -10,6 +10,9 @@ #' 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 @@ -25,6 +28,12 @@ #' @noRd 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) @@ -120,7 +129,9 @@ confirm_file <- function(replicate_path, version) { #' @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". -#' The default value is "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 @@ -133,7 +144,7 @@ confirm_file <- function(replicate_path, version) { #' @examples #' local_dir <- system.file("extdata", "right", package = "verdata") #' confirm_files(local_dir, "reclutamiento", c(1, 2), version = "v1") -confirm_files <- function(replicates_dir, violation, replicate_nums, version = "v2") { +confirm_files <- function(replicates_dir, violation, replicate_nums, version) { files <- build_path(replicates_dir, violation, replicate_nums) @@ -157,6 +168,10 @@ confirm_files <- function(replicates_dir, violation, replicate_nums, version = " 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 2bbc8f3..1e3b903 100644 --- a/R/read_replicates.R +++ b/R/read_replicates.R @@ -10,6 +10,9 @@ #' 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. @@ -28,6 +31,12 @@ #' @noRd 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) @@ -134,7 +143,9 @@ read_replicate <- function(replicate_path, version) { #' @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". -#' The default value is "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 @@ -149,7 +160,13 @@ read_replicate <- function(replicate_path, version) { #' local_dir <- system.file("extdata", "right", package = "verdata") #' read_replicates(local_dir, "reclutamiento", 1, 2, version = "v1") read_replicates <- function(replicates_dir, violation, replicate_nums, - version = "v2", 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, version = version) diff --git a/man/confirm_files.Rd b/man/confirm_files.Rd index e0624d6..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, version = "v2") +confirm_files(replicates_dir, violation, replicate_nums, version) } \arguments{ \item{replicates_dir}{Directory containing the replicates. @@ -18,7 +18,9 @@ letters (homicidio, secuestro, reclutamiento, desaparicion).} 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". -The default value is "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: diff --git a/man/read_replicates.Rd b/man/read_replicates.Rd index 717fccb..d6e8c9c 100644 --- a/man/read_replicates.Rd +++ b/man/read_replicates.Rd @@ -8,7 +8,7 @@ read_replicates( replicates_dir, violation, replicate_nums, - version = "v2", + version, crash = TRUE ) } @@ -25,7 +25,9 @@ and the replicate number preceded by "R", (e.g., "R1" for replicate 1).} 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". -The default value is "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