Skip to content

Commit

Permalink
finalize version argument
Browse files Browse the repository at this point in the history
  • Loading branch information
thegargiulian committed Sep 12, 2024
1 parent 489998b commit b83959e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
19 changes: 17 additions & 2 deletions R/confirm_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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)
Expand Down
21 changes: 19 additions & 2 deletions R/read_replicates.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions man/confirm_files.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/read_replicates.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b83959e

Please sign in to comment.