From 5f7e09a8ace32b1a48d96aa31e22bd87bdd10dec Mon Sep 17 00:00:00 2001 From: Stefan Bundfuss Date: Thu, 14 Nov 2024 16:51:15 +0000 Subject: [PATCH 1/3] #271 add_hms: add hms to xportr.numeric_types and add details to xportr_type() messages --- DESCRIPTION | 2 +- NEWS.md | 8 +++++ R/messages.R | 32 +++++++++++++++-- R/options.R | 68 ++++++++++++++++++------------------- R/split.R | 2 +- R/type.R | 17 ++++++---- R/xportr-package.R | 38 ++++++++++----------- R/zzz.R | 2 +- man/xportr-package.Rd | 41 +++++++++++----------- man/xportr_options.Rd | 68 ++++++++++++++++++------------------- man/xportr_type.Rd | 11 +++--- tests/testthat/test-type.R | 2 +- tests/testthat/test-write.R | 5 ++- 13 files changed, 168 insertions(+), 128 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c424e0f5..f9dae7f2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: xportr Title: Utilities to Output CDISC SDTM/ADaM XPT Files -Version: 0.4.1 +Version: 0.4.2 Authors@R: c( person("Eli", "Miller", , "Eli.Miller@AtorusResearch.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-2127-9456")), diff --git a/NEWS.md b/NEWS.md index b6c80a1e..941d9c91 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,11 @@ +# xportr 0.4.2 + +* `"hms"` was added to the default value of the `xportr.numeric_types` option. +This ensures that `{xportr}` works smoothly with variables created by +`admiral::derive_vars_dtm_to_tm()`. (#271) + +* More details were added to the messages of `xportr_type()`. (#271) + # xportr 0.4.1 ## New Feature diff --git a/R/messages.R b/R/messages.R index e7d49d64..3ab774ef 100644 --- a/R/messages.R +++ b/R/messages.R @@ -88,11 +88,39 @@ type_log <- function(meta_ordered, type_mismatch_ind, verbose) { if (length(type_mismatch_ind) > 0) { cli_h2("Variable type mismatches found.") - cli_alert_success("{ length(type_mismatch_ind) } variables coerced") + cli_alert_success("{ length(type_mismatch_ind) } variable{?s} coerced") + meta_mismatch <- meta_ordered[type_mismatch_ind, ] message <- glue( "Variable type(s) in dataframe don't match metadata: ", - "{encode_vars(meta_ordered[type_mismatch_ind, 'variable'])}" + "{encode_vars(meta_ordered[type_mismatch_ind, 'variable'])}\n", + paste0( + "- `", meta_mismatch$variable, "` was coerced to ", + ifelse(meta_mismatch$type.y == "_character", "", ""), + ". (type in data: ", meta_mismatch$orig_type_data, ", type in metadata: ", + meta_mismatch$orig_type_meta, ")", + collapse = "\n" + ), + paste( + "\ni Types in metadata considered as character (xportr.character_metadata_types option):", + encode_vals(getOption("xportr.character_metadata_types")), + collapse = " " + ), + paste( + "\ni Types in metadata considered as numeric (xportr.numeric_metadata_types option):", + encode_vals(getOption("xportr.numeric_metadata_types")), + collapse = " " + ), + paste( + "\ni Types in data considered as character (xportr.character_types option):", + encode_vals(getOption("xportr.character_types")), + collapse = " " + ), + paste( + "\ni Types in data considered as numeric (xportr.numeric_types option):", + encode_vals(getOption("xportr.numeric_types")), + collapse = " " + ) ) xportr_logger(message, verbose) diff --git a/R/options.R b/R/options.R index c27628fa..60b75c44 100644 --- a/R/options.R +++ b/R/options.R @@ -15,42 +15,42 @@ #' @section Options with `options()`: #' #' \describe{ -#' \item{xportr.df_domain_name}{defaults to `"dataset"`}: -#' The name of the domain "name" column in dataset metadata. -#' \item{xportr.df_label}{defaults to `"label"`}: -#' The column noting the dataset label in dataset metadata. -#' \item{xportr.domain_name}{defaults to `"dataset"`}: -#' The name of the domain "name" column in variable metadata. -#' \item{xportr.variable_name}{defaults to `"variable"`}: -#' The name of the variable "name" in variable metadata. -#' \item{xportr.type_name}{defaults to `"type"`}: -#' The name of the variable type column in variable metadata. -#' \item{xportr.label}{defaults to `"label"`}: -#' The name of the variable label column in variable metadata. -#' \item{xportr.length}{defaults to `"length"`}: -#' The name of the variable length column in variable metadata. -#' \item{xportr.order_name}{defaults to `"order"`}: -#' The name of the variable order column in variable metadata. -#' \item{xportr.format_name}{defaults to `"format"`}: -#' The name of the variable format column in variable metadata. -#' \item{xportr.format_verbose}{defaults to `"none"`}: -#' The default argument for the 'verbose' argument for `xportr_format`. -#' \item{xportr.label_verbose}{defaults to `"none"`}: -#' The default argument for the 'verbose' argument for `xportr_label`. -#' \item{xportr.length_verbose}{defaults to `"none"`}: -#' The default argument for the 'verbose' argument for `xportr_length`. -#' \item{xportr.type_verbose}{defaults to `"label"`}: -#' The default argument for the 'verbose' argument for `xportr_type`. -#' \item{xportr.character_types}{defaults to `"character"`}: -#' The default character vector used to explicitly coerce R classes to character XPT types. +#' \item{xportr.df_domain_name}{defaults to `"dataset"`\cr +#' The name of the domain "name" column in dataset metadata.} +#' \item{xportr.df_label}{defaults to `"label"`\cr +#' The column noting the dataset label in dataset metadata.} +#' \item{xportr.domain_name}{defaults to `"dataset"`\cr +#' The name of the domain "name" column in variable metadata.} +#' \item{xportr.variable_name}{defaults to `"variable"`\cr +#' The name of the variable "name" in variable metadata.} +#' \item{xportr.type_name}{defaults to `"type"`\cr +#' The name of the variable type column in variable metadata.} +#' \item{xportr.label}{defaults to `"label"`\cr +#' The name of the variable label column in variable metadata.} +#' \item{xportr.length}{defaults to `"length"`\cr +#' The name of the variable length column in variable metadata.} +#' \item{xportr.order_name}{defaults to `"order"`\cr +#' The name of the variable order column in variable metadata.} +#' \item{xportr.format_name}{defaults to `"format"`\cr +#' The name of the variable format column in variable metadata.} +#' \item{xportr.format_verbose}{defaults to `"none"`\cr +#' The default argument for the 'verbose' argument for `xportr_format`.} +#' \item{xportr.label_verbose}{defaults to `"none"`\cr +#' The default argument for the 'verbose' argument for `xportr_label`.} +#' \item{xportr.length_verbose}{defaults to `"none"`\cr +#' The default argument for the 'verbose' argument for `xportr_length`.} +#' \item{xportr.type_verbose}{defaults to `"label"`\cr +#' The default argument for the 'verbose' argument for `xportr_type`.} +#' \item{xportr.character_types}{defaults to `"character"`\cr +#' The default character vector used to explicitly coerce R classes to character XPT types.} #' \item{xportr.character_metadata_types}{defaults to `c("character", "char", "text", "date", "posixct", "posixt", #' "datetime", "time", "partialdate", "partialtime", "partialdatetime", -#' "incompletedatetime", "durationdatetime", "intervaldatetime")`}: -#' The default character vector used to explicitly coerce R classes to character XPT types. -#' \item{xportr.numeric_metadata_types}{defaults to `c("integer", "numeric", "num", "float")`}: -#' The default character vector used to explicitly coerce R classes to numeric XPT types. -#' \item{xportr.numeric_types}{defaults to `c("integer", "float", "numeric", "posixct", "posixt", "time", "date")`}: -#' The default character vector used to explicitly coerce R classes to numeric XPT types. +#' "incompletedatetime", "durationdatetime", "intervaldatetime")`\cr +#' The default character vector used to explicitly coerce R classes to character XPT types.} +#' \item{xportr.numeric_metadata_types}{defaults to `c("integer", "numeric", "num", "float")`\cr +#' The default character vector used to explicitly coerce R classes to numeric XPT types.} +#' \item{xportr.numeric_types}{defaults to ``r deparse(getOption("xportr.numeric_types"), width.cutoff = 500)``\cr +#' The default character vector used to explicitly coerce R classes to numeric XPT types.} #' } #' #' @section Options with `xportr_options()`: diff --git a/R/split.R b/R/split.R index ee9c396c..88e74ea4 100644 --- a/R/split.R +++ b/R/split.R @@ -36,7 +36,7 @@ #' adlb <- xportr_split(adlb, "LBCAT") xportr_split <- function(.df, split_by = NULL) { lifecycle::deprecate_warn( - when = "0.5.0", + when = "0.4.1", what = "xportr_split()", with = "xportr_write()", details = "Please use the argument `max_gb_size` in the diff --git a/R/type.R b/R/type.R index 6ad58c2c..963e756a 100644 --- a/R/type.R +++ b/R/type.R @@ -1,11 +1,12 @@ #' Coerce variable type #' -#' XPT v5 datasets only have data types of character and numeric. `xportr_type` +#' XPT v5 datasets only have data types of character and numeric. `xportr_type()` #' attempts to collapse R classes to those two XPT types. The #' 'xportr.character_types' option is used to explicitly collapse the class of a -#' column to character using `as.character`. Similarly, 'xportr.numeric_types' -#' will collapse a column to a numeric type. If no type is passed for a -#' variable, it is assumed to be numeric and coerced with `as.numeric()`. +#' column to character using `as.character()`. Similarly, 'xportr.numeric_types' +#' will collapse a column to a numeric type. (See `xportr_options()` for default +#' values of these options.) If no type is passed for a variable, it is assumed +#' to be numeric and coerced with `as.numeric()`. #' #' Certain care should be taken when using timing variables. R serializes dates #' based on a reference date of 01/01/1970 where XPT uses 01/01/1960. This can @@ -17,7 +18,7 @@ #' #' @section Messaging: `type_log()` is the primary messaging tool for #' `xportr_type()`. The number of column types that mismatch the reported type -#' in the metadata, if any, is reported by by `xportr_type()`. If there are any +#' in the metadata, if any, is reported by `xportr_type()`. If there are any #' type mismatches, and the 'verbose' argument is 'stop', 'warn', or #' 'message', each mismatch will be detailed with the actual type in the data #' and the type noted in the metadata. @@ -132,6 +133,8 @@ xportr_type <- function(.df, by = "variable" ) %>% mutate( + orig_type_data = type.x, + orig_type_meta = type.y, # _character is used here as a mask of character, in case someone doesn't # want 'character' coerced to character type.x = if_else(type.x %in% character_types, "_character", type.x), @@ -154,11 +157,11 @@ xportr_type <- function(.df, # Check if variable types match is_correct <- vapply(meta_ordered[["type.x"]] == meta_ordered[["type.y"]], isTRUE, logical(1)) - # Use the original variable iff metadata is missing that variable + # Use the original variable if metadata is missing that variable correct_type <- ifelse(is.na(meta_ordered[["type.y"]]), meta_ordered[["type.x"]], meta_ordered[["type.y"]]) # Walk along the columns and coerce the variables. Modifying the columns - # Directly instead of something like map_dfc to preserve any attributes. + # directly instead of something like map_dfc to preserve any attributes. iwalk( correct_type, function(x, i, is_correct) { diff --git a/R/xportr-package.R b/R/xportr-package.R index 53b95472..7855f454 100644 --- a/R/xportr-package.R +++ b/R/xportr-package.R @@ -12,82 +12,82 @@ #' \itemize{ #' \item{ #' xportr.df_domain_name - The name of the domain "name" column in dataset -#' metadata. Default: "dataset" +#' metadata. Default: `"dataset"` #' } #' \item { #' xportr.df_label - The column noting the dataset label in dataset metadata. -#' Default: "label" +#' Default: `"label"` #' } #' \item{ #' xportr.domain_name - The name of the domain "name" column in variable -#' metadata. Default: "dataset" +#' metadata. Default: `"dataset"` #' } #' \item{ #' xportr.variable_name - The name of the variable "name" in variable -#' metadata. Default: "variable" +#' metadata. Default: `"variable"` #' } #' \item{ #' xportr.type_name - The name of the variable type column in variable -#' metadata. Default: "type" +#' metadata. Default: `"type"` #' } #' \item{ #' xportr.label - The name of the variable label column in variable metadata. -#' Default: "label" +#' Default: `"label"` #' } #' \item{ #' xportr.length - The name of the variable length column in variable -#' metadata. Default: "length" +#' metadata. Default: `"length"` #' } #' \item{ #' xportr.order_name - The name of the variable order column in variable -#' metadata. Default: "order" +#' metadata. Default: `"order"` #' } #' \item{ #' xportr.format_name - The name of the variable format column in variable -#' metadata. Default: "format" +#' metadata. Default: `"format"` #' } #' \item{ #' xportr.format_verbose - The default argument for the 'verbose' argument for -#' `xportr_format`. Default: "none" +#' `xportr_format`. Default: `"none"` #' } #' \item{ #' xportr.label_verbose - The default argument for the 'verbose' argument for -#' `xportr_label`. Default: "none" +#' `xportr_label`. Default: `"none"` #' } #' \item{ #' xportr.length_verbose - The default argument for the 'verbose' argument for -#' `xportr_length`. Default: "none" +#' `xportr_length`. Default: `"none"` #' } #' \item{ #' xportr.type_verbose - The default argument for the 'verbose' argument for -#' `xportr_type`. Default: "none" +#' `xportr_type`. Default: `"none"` #' } #' \item{ #' xportr.character_types - The default character vector used to explicitly -#' coerce R classes to character XPT types. Default: "character" +#' coerce R classes to character XPT types. Default: `"character"` #' } #' \item{ #' xportr.character_metadata_types - The default character vector used to explicitly -#' coerce R classes to character XPT types. Default: c("character", "char", +#' coerce R classes to character XPT types. Default: `c("character", "char", #' "text", "date", "posixct", "posixt", "datetime", "time", "partialdate", #' "partialtime", "partialdatetime", "incompletedatetime", "durationdatetime", #' "intervaldatetime")` #' } #' \item{ #' xportr.numeric_metadata_types - The default character vector used to explicitly -#' coerce R classes to numeric XPT types. Default: c("integer", "numeric", "num", "float") +#' coerce R classes to numeric XPT types. Default: `c("integer", "numeric", "num", "float")` #' } #' \item{ #' xportr.numeric_types - The default character vector used to explicitly -#' coerce R classes to numeric XPT types. Default: c("integer", "float", -#' "numeric", "posixct", "posixt", "time", "date") +#' coerce R classes to numeric XPT types. Default: +#' ``r deparse(getOption("xportr.numeric_types"), width.cutoff = 500)`` #' } #' } #' #' @section Updating Options: #' \itemize{ #' \item{For a single session, an option can be changed by -#' `option( = )`} +#' `options( = )`.} #' \item{To change an option for a single projects across sessions in that #' projects, place the options update in the `.Rprofile` in that project #' directory.} diff --git a/R/zzz.R b/R/zzz.R index db793471..70ef8c9e 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -33,7 +33,7 @@ xportr_options_list <- list( ), xportr.numeric_types = getOption( "xportr.numeric_types", - c("integer", "float", "numeric", "posixct", "posixt", "time", "date") + c("integer", "float", "numeric", "posixct", "posixt", "time", "date", "hms") ) ) diff --git a/man/xportr-package.Rd b/man/xportr-package.Rd index d077e53c..986d9bb7 100644 --- a/man/xportr-package.Rd +++ b/man/xportr-package.Rd @@ -18,75 +18,72 @@ customize how \code{xportr} works in your environment. \itemize{ \item{ xportr.df_domain_name - The name of the domain "name" column in dataset -metadata. Default: "dataset" +metadata. Default: \code{"dataset"} } \item { xportr.df_label - The column noting the dataset label in dataset metadata. -Default: "label" +Default: \code{"label"} } \item{ xportr.domain_name - The name of the domain "name" column in variable -metadata. Default: "dataset" +metadata. Default: \code{"dataset"} } \item{ xportr.variable_name - The name of the variable "name" in variable -metadata. Default: "variable" +metadata. Default: \code{"variable"} } \item{ xportr.type_name - The name of the variable type column in variable -metadata. Default: "type" +metadata. Default: \code{"type"} } \item{ xportr.label - The name of the variable label column in variable metadata. -Default: "label" +Default: \code{"label"} } \item{ xportr.length - The name of the variable length column in variable -metadata. Default: "length" +metadata. Default: \code{"length"} } \item{ xportr.order_name - The name of the variable order column in variable -metadata. Default: "order" +metadata. Default: \code{"order"} } \item{ xportr.format_name - The name of the variable format column in variable -metadata. Default: "format" +metadata. Default: \code{"format"} } \item{ xportr.format_verbose - The default argument for the 'verbose' argument for -\code{xportr_format}. Default: "none" +\code{xportr_format}. Default: \code{"none"} } \item{ xportr.label_verbose - The default argument for the 'verbose' argument for -\code{xportr_label}. Default: "none" +\code{xportr_label}. Default: \code{"none"} } \item{ xportr.length_verbose - The default argument for the 'verbose' argument for -\code{xportr_length}. Default: "none" +\code{xportr_length}. Default: \code{"none"} } \item{ xportr.type_verbose - The default argument for the 'verbose' argument for -\code{xportr_type}. Default: "none" +\code{xportr_type}. Default: \code{"none"} } \item{ xportr.character_types - The default character vector used to explicitly -coerce R classes to character XPT types. Default: "character" +coerce R classes to character XPT types. Default: \code{"character"} } \item{ xportr.character_metadata_types - The default character vector used to explicitly -coerce R classes to character XPT types. Default: c("character", "char", -"text", "date", "posixct", "posixt", "datetime", "time", "partialdate", -"partialtime", "partialdatetime", "incompletedatetime", "durationdatetime", -"intervaldatetime")` +coerce R classes to character XPT types. Default: \code{c("character", "char", "text", "date", "posixct", "posixt", "datetime", "time", "partialdate", "partialtime", "partialdatetime", "incompletedatetime", "durationdatetime", "intervaldatetime")} } \item{ xportr.numeric_metadata_types - The default character vector used to explicitly -coerce R classes to numeric XPT types. Default: c("integer", "numeric", "num", "float") +coerce R classes to numeric XPT types. Default: \code{c("integer", "numeric", "num", "float")} } \item{ xportr.numeric_types - The default character vector used to explicitly -coerce R classes to numeric XPT types. Default: c("integer", "float", -"numeric", "posixct", "posixt", "time", "date") +coerce R classes to numeric XPT types. Default: +\code{c("integer", "float", "numeric", "posixct", "posixt", "time", "date", "hms")} } } } @@ -95,7 +92,7 @@ coerce R classes to numeric XPT types. Default: c("integer", "float", \itemize{ \item{For a single session, an option can be changed by -\verb{option( = )}} +\verb{options( = )}.} \item{To change an option for a single projects across sessions in that projects, place the options update in the \code{.Rprofile} in that project directory.} diff --git a/man/xportr_options.Rd b/man/xportr_options.Rd index 9c07d0ad..e7fe89cf 100644 --- a/man/xportr_options.Rd +++ b/man/xportr_options.Rd @@ -23,40 +23,40 @@ xportr related options of this type are prefixed with \code{"xportr."}. \describe{ -\item{xportr.df_domain_name}{defaults to \code{"dataset"}}: -The name of the domain "name" column in dataset metadata. -\item{xportr.df_label}{defaults to \code{"label"}}: -The column noting the dataset label in dataset metadata. -\item{xportr.domain_name}{defaults to \code{"dataset"}}: -The name of the domain "name" column in variable metadata. -\item{xportr.variable_name}{defaults to \code{"variable"}}: -The name of the variable "name" in variable metadata. -\item{xportr.type_name}{defaults to \code{"type"}}: -The name of the variable type column in variable metadata. -\item{xportr.label}{defaults to \code{"label"}}: -The name of the variable label column in variable metadata. -\item{xportr.length}{defaults to \code{"length"}}: -The name of the variable length column in variable metadata. -\item{xportr.order_name}{defaults to \code{"order"}}: -The name of the variable order column in variable metadata. -\item{xportr.format_name}{defaults to \code{"format"}}: -The name of the variable format column in variable metadata. -\item{xportr.format_verbose}{defaults to \code{"none"}}: -The default argument for the 'verbose' argument for \code{xportr_format}. -\item{xportr.label_verbose}{defaults to \code{"none"}}: -The default argument for the 'verbose' argument for \code{xportr_label}. -\item{xportr.length_verbose}{defaults to \code{"none"}}: -The default argument for the 'verbose' argument for \code{xportr_length}. -\item{xportr.type_verbose}{defaults to \code{"label"}}: -The default argument for the 'verbose' argument for \code{xportr_type}. -\item{xportr.character_types}{defaults to \code{"character"}}: -The default character vector used to explicitly coerce R classes to character XPT types. -\item{xportr.character_metadata_types}{defaults to \code{c("character", "char", "text", "date", "posixct", "posixt", "datetime", "time", "partialdate", "partialtime", "partialdatetime", "incompletedatetime", "durationdatetime", "intervaldatetime")}}: -The default character vector used to explicitly coerce R classes to character XPT types. -\item{xportr.numeric_metadata_types}{defaults to \code{c("integer", "numeric", "num", "float")}}: -The default character vector used to explicitly coerce R classes to numeric XPT types. -\item{xportr.numeric_types}{defaults to \code{c("integer", "float", "numeric", "posixct", "posixt", "time", "date")}}: -The default character vector used to explicitly coerce R classes to numeric XPT types. +\item{xportr.df_domain_name}{defaults to \code{"dataset"}\cr +The name of the domain "name" column in dataset metadata.} +\item{xportr.df_label}{defaults to \code{"label"}\cr +The column noting the dataset label in dataset metadata.} +\item{xportr.domain_name}{defaults to \code{"dataset"}\cr +The name of the domain "name" column in variable metadata.} +\item{xportr.variable_name}{defaults to \code{"variable"}\cr +The name of the variable "name" in variable metadata.} +\item{xportr.type_name}{defaults to \code{"type"}\cr +The name of the variable type column in variable metadata.} +\item{xportr.label}{defaults to \code{"label"}\cr +The name of the variable label column in variable metadata.} +\item{xportr.length}{defaults to \code{"length"}\cr +The name of the variable length column in variable metadata.} +\item{xportr.order_name}{defaults to \code{"order"}\cr +The name of the variable order column in variable metadata.} +\item{xportr.format_name}{defaults to \code{"format"}\cr +The name of the variable format column in variable metadata.} +\item{xportr.format_verbose}{defaults to \code{"none"}\cr +The default argument for the 'verbose' argument for \code{xportr_format}.} +\item{xportr.label_verbose}{defaults to \code{"none"}\cr +The default argument for the 'verbose' argument for \code{xportr_label}.} +\item{xportr.length_verbose}{defaults to \code{"none"}\cr +The default argument for the 'verbose' argument for \code{xportr_length}.} +\item{xportr.type_verbose}{defaults to \code{"label"}\cr +The default argument for the 'verbose' argument for \code{xportr_type}.} +\item{xportr.character_types}{defaults to \code{"character"}\cr +The default character vector used to explicitly coerce R classes to character XPT types.} +\item{xportr.character_metadata_types}{defaults to \code{c("character", "char", "text", "date", "posixct", "posixt", "datetime", "time", "partialdate", "partialtime", "partialdatetime", "incompletedatetime", "durationdatetime", "intervaldatetime")}\cr +The default character vector used to explicitly coerce R classes to character XPT types.} +\item{xportr.numeric_metadata_types}{defaults to \code{c("integer", "numeric", "num", "float")}\cr +The default character vector used to explicitly coerce R classes to numeric XPT types.} +\item{xportr.numeric_types}{defaults to \code{c("integer", "float", "numeric", "posixct", "posixt", "time", "date", "hms")}\cr +The default character vector used to explicitly coerce R classes to numeric XPT types.} } } diff --git a/man/xportr_type.Rd b/man/xportr_type.Rd index db756a56..28c4eccc 100644 --- a/man/xportr_type.Rd +++ b/man/xportr_type.Rd @@ -32,12 +32,13 @@ metadata now renamed with \code{metadata}} Returns the modified table. } \description{ -XPT v5 datasets only have data types of character and numeric. \code{xportr_type} +XPT v5 datasets only have data types of character and numeric. \code{xportr_type()} attempts to collapse R classes to those two XPT types. The 'xportr.character_types' option is used to explicitly collapse the class of a -column to character using \code{as.character}. Similarly, 'xportr.numeric_types' -will collapse a column to a numeric type. If no type is passed for a -variable, it is assumed to be numeric and coerced with \code{as.numeric()}. +column to character using \code{as.character()}. Similarly, 'xportr.numeric_types' +will collapse a column to a numeric type. (See \code{xportr_options()} for default +values of these options.) If no type is passed for a variable, it is assumed +to be numeric and coerced with \code{as.numeric()}. } \details{ Certain care should be taken when using timing variables. R serializes dates @@ -49,7 +50,7 @@ should happen with variables that appear to be used to denote time. \section{Messaging}{ \code{type_log()} is the primary messaging tool for \code{xportr_type()}. The number of column types that mismatch the reported type -in the metadata, if any, is reported by by \code{xportr_type()}. If there are any +in the metadata, if any, is reported by \code{xportr_type()}. If there are any type mismatches, and the 'verbose' argument is 'stop', 'warn', or 'message', each mismatch will be detailed with the actual type in the data and the type noted in the metadata. diff --git a/tests/testthat/test-type.R b/tests/testthat/test-type.R index fec148ec..d1289d6a 100644 --- a/tests/testthat/test-type.R +++ b/tests/testthat/test-type.R @@ -300,7 +300,7 @@ test_that("type Test 10: Var date types (--DTC) coerced as expected and raise me xportr_type() ) %>% expect_message("Variable type mismatches found.") %>% - expect_message("[0-9+] variables coerced") + expect_message("[0-9+] variables? coerced") expect_equal(purrr::map_chr(df2, class), c( STUDYID = "character", USUBJID = "character", diff --git a/tests/testthat/test-write.R b/tests/testthat/test-write.R index e5c46bb8..448b94ee 100644 --- a/tests/testthat/test-write.R +++ b/tests/testthat/test-write.R @@ -310,9 +310,12 @@ test_that("xportr_write Test 17: `split_by` attribute is used to split the data" on.exit(unlink(tmpdir)) dts <- data_to_save() + expect_warning( dts %>% xportr_split(split_by = "X") %>% - xportr_write(path = tmp) + xportr_write(path = tmp), + class = "lifecycle_warning_deprecated" + ) expect_true( file.exists(file.path(tmpdir, "xyz1.xpt")) From 7a88ee02dc94403b40eea84ffc9216855a10938f Mon Sep 17 00:00:00 2001 From: Stefan Bundfuss Date: Thu, 14 Nov 2024 17:01:44 +0000 Subject: [PATCH 2/3] #271 add_hms: use development version --- DESCRIPTION | 2 +- NEWS.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f9dae7f2..c424e0f5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: xportr Title: Utilities to Output CDISC SDTM/ADaM XPT Files -Version: 0.4.2 +Version: 0.4.1 Authors@R: c( person("Eli", "Miller", , "Eli.Miller@AtorusResearch.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-2127-9456")), diff --git a/NEWS.md b/NEWS.md index 941d9c91..9e1c4ce4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# xportr 0.4.2 +# xportr (development version) * `"hms"` was added to the default value of the `xportr.numeric_types` option. This ensures that `{xportr}` works smoothly with variables created by From 483e4b9b171b11e8d7f928103c16bc0cb4362217 Mon Sep 17 00:00:00 2001 From: Stefan Bundfuss Date: Thu, 14 Nov 2024 17:04:00 +0000 Subject: [PATCH 3/3] #271 add_hms: style files --- tests/testthat/test-write.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-write.R b/tests/testthat/test-write.R index 448b94ee..790b99aa 100644 --- a/tests/testthat/test-write.R +++ b/tests/testthat/test-write.R @@ -311,10 +311,10 @@ test_that("xportr_write Test 17: `split_by` attribute is used to split the data" dts <- data_to_save() expect_warning( - dts %>% - xportr_split(split_by = "X") %>% - xportr_write(path = tmp), - class = "lifecycle_warning_deprecated" + dts %>% + xportr_split(split_by = "X") %>% + xportr_write(path = tmp), + class = "lifecycle_warning_deprecated" ) expect_true(