From fc142d80ed3deaaf8da7d7e2b8fe5e0fb3090750 Mon Sep 17 00:00:00 2001 From: Jon Harmon Date: Tue, 7 Oct 2025 05:30:15 -0500 Subject: [PATCH 1/2] Implement `specify_df()` Closes #4 --- DESCRIPTION | 3 +- NAMESPACE | 5 ++ R/aaa-conditions.R | 90 +++++++++++++++++++++++ R/aaa-shared_params.R | 9 ++- R/harmonize_fct.R | 4 +- R/specify_df.R | 21 ++++++ R/specify_fct.R | 4 +- man/dot-check_args_named.Rd | 21 ++++++ man/dot-check_args_spec.Rd | 21 ++++++ man/dot-compile_error_class.Rd | 18 +++++ man/dot-hrmn_abort.Rd | 38 ++++++++++ man/dot-shared_params.Rd | 12 +++ man/harmonize_fct.Rd | 1 + man/reexports.Rd | 17 +++++ man/specify_df.Rd | 30 ++++++++ man/specify_fct.Rd | 5 ++ tests/testthat/_snaps/aaa-conditions.md | 80 ++++++++++++++++++++ tests/testthat/_snaps/specify_df.md | 9 +++ tests/testthat/test-aaa-conditions.R | 98 +++++++++++++++++++++++++ tests/testthat/test-specify_df.R | 41 +++++++++++ tests/testthat/test-specify_fct.R | 2 +- 21 files changed, 522 insertions(+), 7 deletions(-) create mode 100644 R/aaa-conditions.R create mode 100644 R/specify_df.R create mode 100644 man/dot-check_args_named.Rd create mode 100644 man/dot-check_args_spec.Rd create mode 100644 man/dot-compile_error_class.Rd create mode 100644 man/dot-hrmn_abort.Rd create mode 100644 man/reexports.Rd create mode 100644 man/specify_df.Rd create mode 100644 tests/testthat/_snaps/aaa-conditions.md create mode 100644 tests/testthat/_snaps/specify_df.md create mode 100644 tests/testthat/test-aaa-conditions.R create mode 100644 tests/testthat/test-specify_df.R diff --git a/DESCRIPTION b/DESCRIPTION index 929c13a..1532583 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: hrmn Title: Harmonize Datasets -Version: 0.0.0.9002 +Version: 0.0.0.9003 Authors@R: person("Jon", "Harmon", , "jonthegeek@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-4781-4346")) @@ -22,6 +22,7 @@ Language: en-US Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.3 Imports: + cli, fastmatch, rlang, stbl diff --git a/NAMESPACE b/NAMESPACE index 04627fa..55133e4 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,11 @@ # Generated by roxygen2: do not edit by hand +export(caller_arg) +export(caller_env) export(harmonize_fct) +export(specify_df) export(specify_fct) importFrom(fastmatch,"%fin%") importFrom(rlang,"%||%") +importFrom(rlang,caller_arg) +importFrom(rlang,caller_env) diff --git a/R/aaa-conditions.R b/R/aaa-conditions.R new file mode 100644 index 0000000..994888f --- /dev/null +++ b/R/aaa-conditions.R @@ -0,0 +1,90 @@ +#' @importFrom rlang caller_arg +#' @export +rlang::caller_arg + +#' @importFrom rlang caller_env +#' @export +rlang::caller_env + +#' Signal an error with standards applied +#' +#' A wrapper around [cli::cli_abort()] to throw classed errors. +#' +#' @param message (`character`) The message for the new error. Messages will be +#' formatted with [cli::cli_bullets()]. +#' @param ... Additional parameters passed to [cli::cli_abort()] and on to +#' [rlang::abort()]. +#' @inheritParams .shared_params +#' @keywords internal +.hrmn_abort <- function( + message, + subclass, + call = caller_env(), + message_env = call, + parent = NULL, + ... +) { + cli::cli_abort( + message, + class = c( + .compile_error_class("hrmn", "error", subclass), + .compile_error_class("hrmn", "error"), + .compile_error_class("hrmn", "condition") + ), + call = call, + .envir = message_env, + parent = parent, + ... + ) +} + +#' Compile an error class +#' +#' @param ... `(character)` Components of the class name. +#' @returns A length-1 character vector. +#' @keywords internal +.compile_error_class <- function(...) { + paste(..., sep = "-") +} + +#' Check that all specified args are named +#' +#' @param ... Arguments to check. +#' @inheritParams .shared_params +#' @returns `NULL`, invisibly. +#' @keywords internal +.check_args_named <- function(..., call = rlang::caller_env()) { + if (...length() && (is.null(...names()) || !all(nzchar(...names())))) { + .hrmn_abort( + "All arguments must be named.", + "args_unnamed", + call = call + ) + } + invisible(NULL) +} + +#' Check that all args are hrmn_spec objects +#' +#' @param ... Arguments to check. +#' @inheritParams .shared_params +#' @returns `NULL`, invisibly. +#' @keywords internal +.check_args_spec <- function(..., call = rlang::caller_env()) { + dots <- list(...) + is_spec <- vapply(dots, inherits, logical(1), "hrmn_spec") + if (length(dots) && !all(is_spec)) { + bad_args <- rlang::names2(is_spec)[!is_spec] + bad_args[bad_args == ""] <- "" + .hrmn_abort( + c( + "All arguments must be `hrmn_spec` objects.", + "x" = "Argument{?s} {.arg {bad_args}} {?is/are} not {?a / }`hrmn_spec` object{?s}." + ), + subclass = "args_not_spec", + call = call, + message_env = rlang::current_env() + ) + } + invisible(NULL) +} diff --git a/R/aaa-shared_params.R b/R/aaa-shared_params.R index eabf2a2..bb5198c 100644 --- a/R/aaa-shared_params.R +++ b/R/aaa-shared_params.R @@ -2,8 +2,15 @@ #' #' Reused parameter definitions are gathered here for easier editing. #' +#' @param call `(environment)` The execution environment to mention as the +#' source of error messages. #' @param levels (`character`) The allowed values of the factor. -#' +#' @param message_env (`environment`) The execution environment to use to +#' evaluate variables in error messages. +#' @param parent A parent condition, as you might create during a +#' [rlang::try_fetch()]. See [rlang::abort()] for additional information. +#' @param subclass (`character`) Class(es) to assign to the error. Will be +#' prefixed by "hrmn-error-". #' @name .shared_params #' @keywords internal NULL diff --git a/R/harmonize_fct.R b/R/harmonize_fct.R index 9e1f9c7..6c0d9ac 100644 --- a/R/harmonize_fct.R +++ b/R/harmonize_fct.R @@ -10,8 +10,7 @@ #' are the values in `.data` and the values are the target values. #' #' @returns A harmonized [factor()]. -#' @export -#' +#' @family harmonization functions #' @examples #' # Without a spec, harmonize_fct() acts like [base::factor()]. #' harmonize_fct(c("a", "b", "c")) @@ -28,6 +27,7 @@ #' .spec = spec2, #' .lookup = lookup #' ) +#' @export harmonize_fct <- function(.data, ..., .spec = NULL, .lookup = NULL) { rlang::check_dots_empty() .data <- stbl::to_chr(.data) diff --git a/R/specify_df.R b/R/specify_df.R new file mode 100644 index 0000000..58024ef --- /dev/null +++ b/R/specify_df.R @@ -0,0 +1,21 @@ +#' Data frame specification +#' +#' Create an object that specifies the desired format for a data frame. +#' This specification object does not contain any data itself, only the rules +#' for harmonization. +#' +#' @param ... (`hrmn_spec`) Column specifications, given as named arguments. +#' +#' @returns A `hrmn_df_spec` object that acts as a specification. +#' @family specification functions +#' @examples +#' specify_df( +#' response = specify_fct(levels = c("Yes", "No", "Maybe")), +#' outcome = specify_fct(levels = c("Positive", "Negative")) +#' ) +#' @export +specify_df <- function(...) { + .check_args_named(...) + .check_args_spec(...) + structure(list(...), class = c("hrmn_df_spec", "hrmn_spec", "list")) +} diff --git a/R/specify_fct.R b/R/specify_fct.R index 293aa14..71f58a0 100644 --- a/R/specify_fct.R +++ b/R/specify_fct.R @@ -7,10 +7,10 @@ #' @inheritParams .shared_params #' #' @returns A `hrmn_fct_spec` object that acts as a specification. -#' @export -#' +#' @family specification functions #' @examples #' specify_fct(levels = c("a", "b", "c")) +#' @export specify_fct <- function(levels = character()) { structure( list(levels = stbl::to_chr(levels)), diff --git a/man/dot-check_args_named.Rd b/man/dot-check_args_named.Rd new file mode 100644 index 0000000..29e3de3 --- /dev/null +++ b/man/dot-check_args_named.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/aaa-conditions.R +\name{.check_args_named} +\alias{.check_args_named} +\title{Check that all specified args are named} +\usage{ +.check_args_named(..., call = rlang::caller_env()) +} +\arguments{ +\item{...}{Arguments to check.} + +\item{call}{\code{(environment)} The execution environment to mention as the +source of error messages.} +} +\value{ +\code{NULL}, invisibly. +} +\description{ +Check that all specified args are named +} +\keyword{internal} diff --git a/man/dot-check_args_spec.Rd b/man/dot-check_args_spec.Rd new file mode 100644 index 0000000..811a746 --- /dev/null +++ b/man/dot-check_args_spec.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/aaa-conditions.R +\name{.check_args_spec} +\alias{.check_args_spec} +\title{Check that all args are hrmn_spec objects} +\usage{ +.check_args_spec(..., call = rlang::caller_env()) +} +\arguments{ +\item{...}{Arguments to check.} + +\item{call}{\code{(environment)} The execution environment to mention as the +source of error messages.} +} +\value{ +\code{NULL}, invisibly. +} +\description{ +Check that all args are hrmn_spec objects +} +\keyword{internal} diff --git a/man/dot-compile_error_class.Rd b/man/dot-compile_error_class.Rd new file mode 100644 index 0000000..285ff3c --- /dev/null +++ b/man/dot-compile_error_class.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/aaa-conditions.R +\name{.compile_error_class} +\alias{.compile_error_class} +\title{Compile an error class} +\usage{ +.compile_error_class(...) +} +\arguments{ +\item{...}{\code{(character)} Components of the class name.} +} +\value{ +A length-1 character vector. +} +\description{ +Compile an error class +} +\keyword{internal} diff --git a/man/dot-hrmn_abort.Rd b/man/dot-hrmn_abort.Rd new file mode 100644 index 0000000..d045c51 --- /dev/null +++ b/man/dot-hrmn_abort.Rd @@ -0,0 +1,38 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/aaa-conditions.R +\name{.hrmn_abort} +\alias{.hrmn_abort} +\title{Signal an error with standards applied} +\usage{ +.hrmn_abort( + message, + subclass, + call = caller_env(), + message_env = call, + parent = NULL, + ... +) +} +\arguments{ +\item{message}{(\code{character}) The message for the new error. Messages will be +formatted with \code{\link[cli:cli_bullets]{cli::cli_bullets()}}.} + +\item{subclass}{(\code{character}) Class(es) to assign to the error. Will be +prefixed by "hrmn-error-".} + +\item{call}{\code{(environment)} The execution environment to mention as the +source of error messages.} + +\item{message_env}{(\code{environment}) The execution environment to use to +evaluate variables in error messages.} + +\item{parent}{A parent condition, as you might create during a +\code{\link[rlang:try_fetch]{rlang::try_fetch()}}. See \code{\link[rlang:abort]{rlang::abort()}} for additional information.} + +\item{...}{Additional parameters passed to \code{\link[cli:cli_abort]{cli::cli_abort()}} and on to +\code{\link[rlang:abort]{rlang::abort()}}.} +} +\description{ +A wrapper around \code{\link[cli:cli_abort]{cli::cli_abort()}} to throw classed errors. +} +\keyword{internal} diff --git a/man/dot-shared_params.Rd b/man/dot-shared_params.Rd index 8eb0f4b..e920af7 100644 --- a/man/dot-shared_params.Rd +++ b/man/dot-shared_params.Rd @@ -4,7 +4,19 @@ \alias{.shared_params} \title{Parameters used in multiple functions} \arguments{ +\item{call}{\code{(environment)} The execution environment to mention as the +source of error messages.} + \item{levels}{(\code{character}) The allowed values of the factor.} + +\item{message_env}{(\code{environment}) The execution environment to use to +evaluate variables in error messages.} + +\item{parent}{A parent condition, as you might create during a +\code{\link[rlang:try_fetch]{rlang::try_fetch()}}. See \code{\link[rlang:abort]{rlang::abort()}} for additional information.} + +\item{subclass}{(\code{character}) Class(es) to assign to the error. Will be +prefixed by "hrmn-error-".} } \description{ Reused parameter definitions are gathered here for easier editing. diff --git a/man/harmonize_fct.Rd b/man/harmonize_fct.Rd index bb55d28..ec4e438 100644 --- a/man/harmonize_fct.Rd +++ b/man/harmonize_fct.Rd @@ -41,3 +41,4 @@ harmonize_fct( .lookup = lookup ) } +\concept{harmonization functions} diff --git a/man/reexports.Rd b/man/reexports.Rd new file mode 100644 index 0000000..45ce252 --- /dev/null +++ b/man/reexports.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/aaa-conditions.R +\docType{import} +\name{reexports} +\alias{reexports} +\alias{caller_arg} +\alias{caller_env} +\title{Objects exported from other packages} +\keyword{internal} +\description{ +These objects are imported from other packages. Follow the links +below to see their documentation. + +\describe{ + \item{rlang}{\code{\link[rlang]{caller_arg}}, \code{\link[rlang:stack]{caller_env}}} +}} + diff --git a/man/specify_df.Rd b/man/specify_df.Rd new file mode 100644 index 0000000..ffc60c7 --- /dev/null +++ b/man/specify_df.Rd @@ -0,0 +1,30 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/specify_df.R +\name{specify_df} +\alias{specify_df} +\title{Data frame specification} +\usage{ +specify_df(...) +} +\arguments{ +\item{...}{(\code{hrmn_spec}) Column specifications, given as named arguments.} +} +\value{ +A \code{hrmn_df_spec} object that acts as a specification. +} +\description{ +Create an object that specifies the desired format for a data frame. +This specification object does not contain any data itself, only the rules +for harmonization. +} +\examples{ +specify_df( + response = specify_fct(levels = c("Yes", "No", "Maybe")), + outcome = specify_fct(levels = c("Positive", "Negative")) +) +} +\seealso{ +Other specification functions: +\code{\link{specify_fct}()} +} +\concept{specification functions} diff --git a/man/specify_fct.Rd b/man/specify_fct.Rd index ff3a34e..5a5a31a 100644 --- a/man/specify_fct.Rd +++ b/man/specify_fct.Rd @@ -20,3 +20,8 @@ for harmonization. \examples{ specify_fct(levels = c("a", "b", "c")) } +\seealso{ +Other specification functions: +\code{\link{specify_df}()} +} +\concept{specification functions} diff --git a/tests/testthat/_snaps/aaa-conditions.md b/tests/testthat/_snaps/aaa-conditions.md new file mode 100644 index 0000000..c1e1b13 --- /dev/null +++ b/tests/testthat/_snaps/aaa-conditions.md @@ -0,0 +1,80 @@ +# .hrmn_abort() throws the expected error + + Code + .hrmn_abort("A message.", "a_subclass") + Condition + Error: + ! A message. + +# .hrmn_abort() uses parent when provided + + Code + .hrmn_abort("child message", "child_class", parent = parent_cnd) + Condition + Error: + ! child message + Caused by error: + ! parent message + +# .hrmn_abort() passes dots to cli_abort() + + Code + .hrmn_abort("A message.", "a_subclass", .internal = TRUE) + Condition + Error: + ! A message. + i This is an internal error that was detected in the hrmn package. + Please report it at with a reprex () and the full backtrace. + +# .hrmn_abort() uses message_env when provided + + Code + .hrmn_abort("This message comes from {var}.", "subclass", message_env = msg_env) + Condition + Error: + ! This message comes from a custom environment. + +# .check_args_named() works + + Code + .check_args_named(1) + Condition + Error: + ! All arguments must be named. + +# .check_args_spec() works + + Code + .check_args_spec(a = 1) + Condition + Error: + ! All arguments must be `hrmn_spec` objects. + x Argument `a` is not a `hrmn_spec` object. + +--- + + Code + .check_args_spec(a = 1, b = "B") + Condition + Error: + ! All arguments must be `hrmn_spec` objects. + x Arguments `a` and `b` are not `hrmn_spec` objects. + +--- + + Code + .check_args_spec(a = 1, b = spec) + Condition + Error: + ! All arguments must be `hrmn_spec` objects. + x Argument `a` is not a `hrmn_spec` object. + +--- + + Code + .check_args_spec(1) + Condition + Error: + ! All arguments must be `hrmn_spec` objects. + x Argument `` is not a `hrmn_spec` object. + diff --git a/tests/testthat/_snaps/specify_df.md b/tests/testthat/_snaps/specify_df.md new file mode 100644 index 0000000..eb637fc --- /dev/null +++ b/tests/testthat/_snaps/specify_df.md @@ -0,0 +1,9 @@ +# specify_df() errors if arguments are not hrmn_spec objects + + Code + specify_df(col2 = 123) + Condition + Error in `specify_df()`: + ! All arguments must be `hrmn_spec` objects. + x Argument `col2` is not a `hrmn_spec` object. + diff --git a/tests/testthat/test-aaa-conditions.R b/tests/testthat/test-aaa-conditions.R new file mode 100644 index 0000000..d221e07 --- /dev/null +++ b/tests/testthat/test-aaa-conditions.R @@ -0,0 +1,98 @@ +test_that(".hrmn_abort() throws the expected error", { + expect_error( + .hrmn_abort("A message.", "a_subclass"), + class = "hrmn-error-a_subclass" + ) + expect_error( + .hrmn_abort("A message.", "a_subclass"), + class = "hrmn-error" + ) + expect_error( + .hrmn_abort("A message.", "a_subclass"), + class = "hrmn-condition" + ) + expect_snapshot( + .hrmn_abort("A message.", "a_subclass"), + error = TRUE + ) +}) + +test_that(".hrmn_abort() uses parent when provided", { + parent_cnd <- rlang::catch_cnd(cli::cli_abort("parent message")) + expect_snapshot( + .hrmn_abort("child message", "child_class", parent = parent_cnd), + error = TRUE + ) +}) + +test_that(".hrmn_abort() passes dots to cli_abort()", { + expect_error( + .hrmn_abort("A message.", "a_subclass", .internal = TRUE), + class = "hrmn-error-a_subclass" + ) + expect_snapshot( + .hrmn_abort("A message.", "a_subclass", .internal = TRUE), + error = TRUE + ) +}) + +test_that(".hrmn_abort() uses message_env when provided", { + var <- "a locally defined var" + msg_env <- new.env() + msg_env$var <- "a custom environment" + expect_snapshot( + .hrmn_abort( + "This message comes from {var}.", + "subclass", + message_env = msg_env + ), + error = TRUE + ) +}) + +test_that(".compile_error_class() works", { + expect_equal( + .compile_error_class("hrmn", "error", "my_subclass"), + "hrmn-error-my_subclass" + ) + expect_equal( + .compile_error_class("hrmn", "error"), + "hrmn-error" + ) + expect_equal( + .compile_error_class("hrmn", "condition"), + "hrmn-condition" + ) +}) + +test_that(".check_args_named() works", { + expect_no_error(.check_args_named()) + expect_no_error(.check_args_named(a = 1)) + expect_no_error(.check_args_named(a = 1, b = 2)) + + expect_error(.check_args_named(1), class = "hrmn-error-args_unnamed") + expect_error(.check_args_named(a = 1, 2), class = "hrmn-error-args_unnamed") + expect_error(.check_args_named(1, 2), class = "hrmn-error-args_unnamed") + expect_snapshot(.check_args_named(1), error = TRUE) +}) + +test_that(".check_args_spec() works", { + expect_no_error(.check_args_spec()) + spec <- structure(list(), class = "hrmn_spec") + expect_no_error(.check_args_spec(a = spec)) + expect_no_error(.check_args_spec(a = spec, b = spec)) + + expect_error(.check_args_spec(a = 1), class = "hrmn-error-args_not_spec") + expect_error( + .check_args_spec(a = spec, b = "B"), + class = "hrmn-error-args_not_spec" + ) + expect_error( + .check_args_spec(a = 1, b = 2), + class = "hrmn-error-args_not_spec" + ) + expect_snapshot(.check_args_spec(a = 1), error = TRUE) + expect_snapshot(.check_args_spec(a = 1, b = "B"), error = TRUE) + expect_snapshot(.check_args_spec(a = 1, b = spec), error = TRUE) + expect_snapshot(.check_args_spec(1), error = TRUE) +}) diff --git a/tests/testthat/test-specify_df.R b/tests/testthat/test-specify_df.R new file mode 100644 index 0000000..35657c7 --- /dev/null +++ b/tests/testthat/test-specify_df.R @@ -0,0 +1,41 @@ +test_that("specify_df() returns a hrmn_df_spec object", { + expect_s3_class( + specify_df(), + c("hrmn_df_spec", "hrmn_spec", "list"), + exact = TRUE + ) +}) + +test_that("specify_df() captures a single column specification", { + spec <- specify_fct(levels = c("a", "b")) + expected <- structure( + list(col1 = spec), + class = c("hrmn_df_spec", "hrmn_spec", "list") + ) + expect_identical(specify_df(col1 = spec), expected) +}) + +test_that("specify_df() errors if dots are unnamed", { + expect_error( + specify_df(specify_fct(levels = c("a", "b"))), + class = "hrmn-error-args_unnamed" + ) +}) + +test_that("specify_df() errors if arguments are not hrmn_spec objects", { + expect_error( + specify_df(col1 = "not a spec"), + class = "hrmn-error-args_not_spec" + ) + expect_error( + specify_df( + col1 = specify_fct(levels = c("a", "b")), + col2 = 123 + ), + class = "hrmn-error-args_not_spec" + ) + expect_snapshot( + specify_df(col2 = 123), + error = TRUE + ) +}) diff --git a/tests/testthat/test-specify_fct.R b/tests/testthat/test-specify_fct.R index 9b93283..f5ed687 100644 --- a/tests/testthat/test-specify_fct.R +++ b/tests/testthat/test-specify_fct.R @@ -1,4 +1,4 @@ -test_that("specify_fct() returns an object with the correct class", { +test_that("specify_fct() returns a hrmn_fct_spec object", { expect_s3_class( specify_fct(), c("hrmn_fct_spec", "hrmn_spec", "list"), From ce423496ef98f6a858d2b4306221d18112d9d85a Mon Sep 17 00:00:00 2001 From: Jon Harmon Date: Wed, 8 Oct 2025 05:30:35 -0500 Subject: [PATCH 2/2] Standardize class order. hrmn_fct_spec --> hrmn_spec_fct hrmn_df_spec --> hrmn_spec_df --- R/harmonize_fct.R | 2 +- R/specify_df.R | 4 ++-- R/specify_fct.R | 4 ++-- man/harmonize_fct.Rd | 2 +- man/specify_df.Rd | 2 +- man/specify_fct.Rd | 2 +- tests/testthat/test-specify_df.R | 6 +++--- tests/testthat/test-specify_fct.R | 4 ++-- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/R/harmonize_fct.R b/R/harmonize_fct.R index 6c0d9ac..a1b0bb5 100644 --- a/R/harmonize_fct.R +++ b/R/harmonize_fct.R @@ -4,7 +4,7 @@ #' to the specified factor. #' @inheritParams .shared_params #' @inheritParams rlang::args_dots_empty -#' @param .spec (`hrmn_fct_spec`) A harmonization specification from +#' @param .spec (`hrmn_spec_fct`) A harmonization specification from #' [specify_fct()]. #' @param .lookup (named `character`) A vector of replacement values. The names #' are the values in `.data` and the values are the target values. diff --git a/R/specify_df.R b/R/specify_df.R index 58024ef..98270aa 100644 --- a/R/specify_df.R +++ b/R/specify_df.R @@ -6,7 +6,7 @@ #' #' @param ... (`hrmn_spec`) Column specifications, given as named arguments. #' -#' @returns A `hrmn_df_spec` object that acts as a specification. +#' @returns A `hrmn_spec_df` object that acts as a specification. #' @family specification functions #' @examples #' specify_df( @@ -17,5 +17,5 @@ specify_df <- function(...) { .check_args_named(...) .check_args_spec(...) - structure(list(...), class = c("hrmn_df_spec", "hrmn_spec", "list")) + structure(list(...), class = c("hrmn_spec_df", "hrmn_spec", "list")) } diff --git a/R/specify_fct.R b/R/specify_fct.R index 71f58a0..4d19147 100644 --- a/R/specify_fct.R +++ b/R/specify_fct.R @@ -6,7 +6,7 @@ #' #' @inheritParams .shared_params #' -#' @returns A `hrmn_fct_spec` object that acts as a specification. +#' @returns A `hrmn_spec_fct` object that acts as a specification. #' @family specification functions #' @examples #' specify_fct(levels = c("a", "b", "c")) @@ -14,6 +14,6 @@ specify_fct <- function(levels = character()) { structure( list(levels = stbl::to_chr(levels)), - class = c("hrmn_fct_spec", "hrmn_spec", "list") + class = c("hrmn_spec_fct", "hrmn_spec", "list") ) } diff --git a/man/harmonize_fct.Rd b/man/harmonize_fct.Rd index ec4e438..9a60789 100644 --- a/man/harmonize_fct.Rd +++ b/man/harmonize_fct.Rd @@ -12,7 +12,7 @@ to the specified factor.} \item{...}{These dots are for future extensions and must be empty.} -\item{.spec}{(\code{hrmn_fct_spec}) A harmonization specification from +\item{.spec}{(\code{hrmn_spec_fct}) A harmonization specification from \code{\link[=specify_fct]{specify_fct()}}.} \item{.lookup}{(named \code{character}) A vector of replacement values. The names diff --git a/man/specify_df.Rd b/man/specify_df.Rd index ffc60c7..240ec5e 100644 --- a/man/specify_df.Rd +++ b/man/specify_df.Rd @@ -10,7 +10,7 @@ specify_df(...) \item{...}{(\code{hrmn_spec}) Column specifications, given as named arguments.} } \value{ -A \code{hrmn_df_spec} object that acts as a specification. +A \code{hrmn_spec_df} object that acts as a specification. } \description{ Create an object that specifies the desired format for a data frame. diff --git a/man/specify_fct.Rd b/man/specify_fct.Rd index 5a5a31a..ea34300 100644 --- a/man/specify_fct.Rd +++ b/man/specify_fct.Rd @@ -10,7 +10,7 @@ specify_fct(levels = character()) \item{levels}{(\code{character}) The allowed values of the factor.} } \value{ -A \code{hrmn_fct_spec} object that acts as a specification. +A \code{hrmn_spec_fct} object that acts as a specification. } \description{ Create an object that specifies the desired levels for a factor variable. diff --git a/tests/testthat/test-specify_df.R b/tests/testthat/test-specify_df.R index 35657c7..7adc97f 100644 --- a/tests/testthat/test-specify_df.R +++ b/tests/testthat/test-specify_df.R @@ -1,7 +1,7 @@ -test_that("specify_df() returns a hrmn_df_spec object", { +test_that("specify_df() returns a hrmn_spec_df object", { expect_s3_class( specify_df(), - c("hrmn_df_spec", "hrmn_spec", "list"), + c("hrmn_spec_df", "hrmn_spec", "list"), exact = TRUE ) }) @@ -10,7 +10,7 @@ test_that("specify_df() captures a single column specification", { spec <- specify_fct(levels = c("a", "b")) expected <- structure( list(col1 = spec), - class = c("hrmn_df_spec", "hrmn_spec", "list") + class = c("hrmn_spec_df", "hrmn_spec", "list") ) expect_identical(specify_df(col1 = spec), expected) }) diff --git a/tests/testthat/test-specify_fct.R b/tests/testthat/test-specify_fct.R index f5ed687..9aae10b 100644 --- a/tests/testthat/test-specify_fct.R +++ b/tests/testthat/test-specify_fct.R @@ -1,7 +1,7 @@ -test_that("specify_fct() returns a hrmn_fct_spec object", { +test_that("specify_fct() returns a hrmn_spec_fct object", { expect_s3_class( specify_fct(), - c("hrmn_fct_spec", "hrmn_spec", "list"), + c("hrmn_spec_fct", "hrmn_spec", "list"), exact = TRUE ) })