From e8f2986effce7384a840a0eb19dc71de56348557 Mon Sep 17 00:00:00 2001 From: Chris Hartgerink Date: Thu, 1 Aug 2024 15:44:38 +0200 Subject: [PATCH] Fix errors --- R/make_datatagr.R | 2 +- R/validate_datatagr.R | 7 ++++++- R/validate_tags.R | 7 ++++++- R/validate_types.R | 5 ++++- man/validate_datatagr.Rd | 7 ++++++- man/validate_tags.Rd | 7 ++++++- man/validate_types.Rd | 5 ++++- tests/testthat/test-validate_datatagr.R | 6 ++++-- tests/testthat/test-validate_types.R | 2 +- 9 files changed, 38 insertions(+), 10 deletions(-) diff --git a/R/make_datatagr.R b/R/make_datatagr.R index a1c1153..c8e78c0 100644 --- a/R/make_datatagr.R +++ b/R/make_datatagr.R @@ -8,7 +8,7 @@ #' @param x a `data.frame` or a `tibble` #' #' @param ... <[`dynamic-dots`][rlang::dyn-dots]> A series of tags provided as -#' `tag_name = "column_name"`. When specifying tags, please also see +#' `tag_name = "column_name"`. When specifying tags, please also see #' `tag_defaults` to specify default values. #' #' @param tag_defaults a list of default values for the provided tags. Defaults diff --git a/R/validate_datatagr.R b/R/validate_datatagr.R index 8562848..39a6dcc 100644 --- a/R/validate_datatagr.R +++ b/R/validate_datatagr.R @@ -43,7 +43,12 @@ #' x #' #' ## validation -#' validate_datatagr(x) +#' validate_datatagr(x, ref_types = tags_types( +#' id = c("integer", "factor"), +#' date_onset = "Date", +#' age = "numeric", +#' gender = c("factor", "character") +#' )) #' #' ## create an invalid datatagr - onset date is a factor #' x <- measles_hagelloch_1861 %>% diff --git a/R/validate_tags.R b/R/validate_tags.R index 63beca7..46ad21a 100644 --- a/R/validate_tags.R +++ b/R/validate_tags.R @@ -27,7 +27,12 @@ #' x #' #' ## validation -#' validate_tags(x) +#' validate_datatagr(x, ref_types = tags_types( +#' id = c("integer", "factor"), +#' date_onset = "Date", +#' age = "numeric", +#' gender = c("factor", "character") +#' )) #' #' ## hack to create an invalid tags (missing defaults) #' attr(x, "tags") <- list(id = "case_ID") diff --git a/R/validate_types.R b/R/validate_types.R index b47b2cd..0eca71d 100644 --- a/R/validate_types.R +++ b/R/validate_types.R @@ -32,7 +32,10 @@ #' tryCatch(validate_types(x), error = paste) #' #' ## to allow other types, e.g. gender to be integer, character or factor -#' validate_types(x, tags_types(gender = c("integer", "character", "factor"))) +#' validate_types(x, tags_types(id = "integer", gender = c( +#' "integer", +#' "character", "factor" +#' ))) #' } validate_types <- function(x, ref_types = tags_types()) { checkmate::assert_class(x, "datatagr") diff --git a/man/validate_datatagr.Rd b/man/validate_datatagr.Rd index 63b28ee..cd37e78 100644 --- a/man/validate_datatagr.Rd +++ b/man/validate_datatagr.Rd @@ -46,7 +46,12 @@ if (require(outbreaks) && require(magrittr)) { x ## validation - validate_datatagr(x) + validate_datatagr(x, ref_types = tags_types( + id = c("integer", "factor"), + date_onset = "Date", + age = "numeric", + gender = c("factor", "character") + )) ## create an invalid datatagr - onset date is a factor x <- measles_hagelloch_1861 \%>\% diff --git a/man/validate_tags.Rd b/man/validate_tags.Rd index d07eabb..a68ba4e 100644 --- a/man/validate_tags.Rd +++ b/man/validate_tags.Rd @@ -31,7 +31,12 @@ if (require(outbreaks) && require(magrittr)) { x ## validation - validate_tags(x) + validate_datatagr(x, ref_types = tags_types( + id = c("integer", "factor"), + date_onset = "Date", + age = "numeric", + gender = c("factor", "character") + )) ## hack to create an invalid tags (missing defaults) attr(x, "tags") <- list(id = "case_ID") diff --git a/man/validate_types.Rd b/man/validate_types.Rd index ea833d3..8eed4ae 100644 --- a/man/validate_types.Rd +++ b/man/validate_types.Rd @@ -34,7 +34,10 @@ if (require(outbreaks) && require(magrittr)) { tryCatch(validate_types(x), error = paste) ## to allow other types, e.g. gender to be integer, character or factor - validate_types(x, tags_types(gender = c("integer", "character", "factor"))) + validate_types(x, tags_types(id = "integer", gender = c( + "integer", + "character", "factor" + ))) } } \seealso{ diff --git a/tests/testthat/test-validate_datatagr.R b/tests/testthat/test-validate_datatagr.R index 69c101b..20d14be 100644 --- a/tests/testthat/test-validate_datatagr.R +++ b/tests/testthat/test-validate_datatagr.R @@ -10,8 +10,10 @@ test_that("tests for validate_datatagr", { x <- make_datatagr(cars, gender = "speed") expect_error( - validate_datatagr(x, ref_types = tags_types(gender = c('character', - 'factor'))), + validate_datatagr(x, ref_types = tags_types(gender = c( + "character", + "factor" + ))), "- gender: Must inherit from class 'character'/'factor'" ) diff --git a/tests/testthat/test-validate_types.R b/tests/testthat/test-validate_types.R index b584f20..4d5626b 100644 --- a/tests/testthat/test-validate_types.R +++ b/tests/testthat/test-validate_types.R @@ -11,7 +11,7 @@ test_that("validate_types() validates types", { expect_silent( expect_identical( x, - validate_types(x, ref_types = tags_types(age = 'numeric')) + validate_types(x, ref_types = tags_types(age = "numeric")) ) )