From 21676a6544696b3b2edcce0bb354ae1e4f394f5c Mon Sep 17 00:00:00 2001 From: Celine Date: Fri, 22 Dec 2023 04:55:41 -0500 Subject: [PATCH 01/17] Add metadata type --- R/type.R | 8 +++++--- R/zzz.R | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/R/type.R b/R/type.R index 86d6bd15..65d8ec40 100644 --- a/R/type.R +++ b/R/type.R @@ -93,6 +93,8 @@ xportr_type <- function(.df, variable_name <- getOption("xportr.variable_name") type_name <- getOption("xportr.type_name") characterTypes <- c(getOption("xportr.character_types"), "_character") + characterMetadataTypes <- c(getOption("xportr.character_metadata_types"), "_character") + numericMetadataTypes <- c(getOption("xportr.numeric_metadata_types"), "_numeric") numericTypes <- c(getOption("xportr.numeric_types"), "_numeric") format_name <- getOption("xportr.format_name") @@ -137,14 +139,14 @@ xportr_type <- function(.df, # _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% characterTypes, "_character", type.x), - type.x = if_else(type.x %in% numericTypes | (grepl("DT$|DTM$|TM$", variable) & !is.na(format)), + type.x = if_else(type.x %in% numericTypes, "_numeric", type.x ), type.y = if_else(is.na(type.y), type.x, type.y), type.y = tolower(type.y), - type.y = if_else(type.y %in% characterTypes | (grepl("DTC$", variable) & is.na(format)), "_character", type.y), - type.y = if_else(type.y %in% numericTypes, "_numeric", type.y) + type.y = if_else(type.y %in% characterMetadataTypes, "_character", type.y), + type.y = if_else(type.y %in% numericMetadataTypes, "_numeric", type.y) ) # It is possible that a variable exists in the table that isn't in the metadata diff --git a/R/zzz.R b/R/zzz.R index 88b877b5..6b8ef834 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -13,14 +13,16 @@ xportr.label_verbose = "none", xportr.length_verbose = "none", xportr.type_verbose = "none", - xportr.character_types = c( + xportr.character_types = c("character"), + xportr.character_metadata_types = c( "character", "char", "text", "date", "posixct", "posixt", "datetime", "time", "partialdate", "partialtime", "partialdatetime", "incompletedatetime", "durationdatetime", "intervaldatetime" ), - xportr.numeric_types = c("integer", "numeric", "num", "float"), + xportr.numeric_metadata_types = c("integer", "numeric", "num", "float"), + xportr.numeric_types = c("integer", "float", "posixct", "posixt", "time", "date"), xportr.order_name = "order" ) toset <- !(names(op.devtools) %in% names(op)) From ce0b5e4389a3963c5fdfd1bcfa08e3669d0fccae Mon Sep 17 00:00:00 2001 From: Celine Date: Wed, 10 Jan 2024 06:10:03 -0500 Subject: [PATCH 02/17] Add test for date coercion to character --- tests/testthat/test-type.R | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/testthat/test-type.R b/tests/testthat/test-type.R index c593fdb1..5f2a54d5 100644 --- a/tests/testthat/test-type.R +++ b/tests/testthat/test-type.R @@ -300,3 +300,38 @@ test_that("xportr_type: Drops factor levels", { expect_null(attributes(df2$Val)) }) + + +df <- data.frame( + STUDYID = c("PILOT01", "PILOT01", "PILOT01"), + USUBJID = c("01-1130", "01-1133", "01-1133"), + TRTEDT = c("2014-08-16", "2013-04-28", "2013-01-12") +) %>% + mutate( + TRTEDT = as.Date(TRTEDT), + EXSTDTC = TRTEDT + ) + +metadata <- data.frame( + dataset = c("df", "df", "df", "df"), + variable = c("STUDYID", "USUBJID", "TRTEDT", "EXSTDTC"), + type = c("character", "character", "numeric", "date"), + format = c(NA, NA, "DATE9.", NA) +) + +test_that("xportr_metadata: Var date types (--DTC) coerced as expected and raise messages", { + # Remove empty lines in cli theme + local_cli_theme() + + ( + df2 <- xportr_metadata(df, metadata) %>% + xportr_type() + ) %>% + expect_message("Variable type mismatches found.") %>% + expect_message("[0-9+] variables coerced") + + expect_equal(purrr::map_chr(df2, class), c( + STUDYID = "character", USUBJID = "character", + TRTEDT = "Date", EXSTDTC = "character" + )) +}) From 1f50d9b4a88638b38c8528c944ba58493228f26d Mon Sep 17 00:00:00 2001 From: Celine Date: Fri, 12 Jan 2024 02:57:27 -0500 Subject: [PATCH 03/17] Update test-length for datetime variables --- tests/testthat/test-length.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-length.R b/tests/testthat/test-length.R index 35761d84..91ecb38f 100644 --- a/tests/testthat/test-length.R +++ b/tests/testthat/test-length.R @@ -198,8 +198,8 @@ test_that("xportr_length: Column length of known/unkown character types is 200/8 expect_equal(impute_length(123), 8) expect_equal(impute_length(123L), 8) expect_equal(impute_length("string"), 200) - expect_equal(impute_length(Sys.Date()), 200) - expect_equal(impute_length(Sys.time()), 200) + expect_equal(impute_length(Sys.Date()), 8) + expect_equal(impute_length(Sys.time()), 8) withr::local_options(list(xportr.character_types = c("character", "date"))) expect_equal(impute_length(Sys.time()), 8) From 9625a773a799217de20cf9dfcbd22fa1efaf7e9c Mon Sep 17 00:00:00 2001 From: Celine Date: Fri, 12 Jan 2024 04:45:13 -0500 Subject: [PATCH 04/17] Remove format from type --- R/type.R | 18 ++++++------------ man/xportr_type.Rd | 6 +----- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/R/type.R b/R/type.R index 65d8ec40..34ab1dfc 100644 --- a/R/type.R +++ b/R/type.R @@ -36,24 +36,20 @@ #' "dataset". This is the column subset by the 'domain' argument in the #' function. #' -#' 2) Format Name - passed as the 'xportr.format_name' option. Default: -#' "format". Character values to update the 'format.sas' attribute of the -#' column. This is passed to `haven::write` to note the format. -#' -#' 3) Variable Name - passed as the 'xportr.variable_name' option. Default: +#' 2) Variable Name - passed as the 'xportr.variable_name' option. Default: #' "variable". This is used to match columns in '.df' argument and the #' metadata. #' -#' 4) Variable Type - passed as the 'xportr.type_name'. Default: "type". This +#' 3) Variable Type - passed as the 'xportr.type_name'. Default: "type". This #' is used to note the XPT variable "type" options are numeric or character. #' -#' 5) (Option only) Character Types - The list of classes that should be +#' 4) (Option only) Character Types - The list of classes that should be #' explicitly coerced to a XPT Character type. Default: c( "character", #' "char", "text", "date", "posixct", "posixt", "datetime", "time", #' "partialdate", "partialtime", "partialdatetime", "incompletedatetime", #' "durationdatetime", "intervaldatetime") #' -#' 6) (Option only) Numeric Types - The list of classes that should be +#' 5) (Option only) Numeric Types - The list of classes that should be #' explicitly coerced to a XPT numeric type. Default: c("integer", "numeric", #' "num", "float") #' @@ -64,8 +60,7 @@ #' metadata <- data.frame( #' dataset = "test", #' variable = c("Subj", "Param", "Val", "NotUsed"), -#' type = c("numeric", "character", "numeric", "character"), -#' format = NA +#' type = c("numeric", "character", "numeric", "character") #' ) #' #' .df <- data.frame( @@ -96,7 +91,6 @@ xportr_type <- function(.df, characterMetadataTypes <- c(getOption("xportr.character_metadata_types"), "_character") numericMetadataTypes <- c(getOption("xportr.numeric_metadata_types"), "_numeric") numericTypes <- c(getOption("xportr.numeric_types"), "_numeric") - format_name <- getOption("xportr.format_name") ## Common section to detect domain from argument or pipes @@ -121,7 +115,7 @@ xportr_type <- function(.df, } metacore <- metadata %>% - select(!!sym(variable_name), !!sym(type_name), !!sym(format_name)) + select(!!sym(variable_name), !!sym(type_name)) # Common check for multiple variables name check_multiple_var_specs(metadata, variable_name) diff --git a/man/xportr_type.Rd b/man/xportr_type.Rd index abfa41d8..1a49735b 100644 --- a/man/xportr_type.Rd +++ b/man/xportr_type.Rd @@ -70,9 +70,6 @@ For data.frame 'metadata' arguments four columns must be present: \item Domain Name - passed as the 'xportr.domain_name' option. Default: "dataset". This is the column subset by the 'domain' argument in the function. -\item Format Name - passed as the 'xportr.format_name' option. Default: -"format". Character values to update the 'format.sas' attribute of the -column. This is passed to \code{haven::write} to note the format. \item Variable Name - passed as the 'xportr.variable_name' option. Default: "variable". This is used to match columns in '.df' argument and the metadata. @@ -93,8 +90,7 @@ explicitly coerced to a XPT numeric type. Default: c("integer", "numeric", metadata <- data.frame( dataset = "test", variable = c("Subj", "Param", "Val", "NotUsed"), - type = c("numeric", "character", "numeric", "character"), - format = NA + type = c("numeric", "character", "numeric", "character") ) .df <- data.frame( From 1841c4e62206a4fa585763176addeb421aa7fce0 Mon Sep 17 00:00:00 2001 From: Celine Date: Wed, 17 Jan 2024 05:37:54 -0500 Subject: [PATCH 05/17] Udpate function description to remove reference to DT, DTM and TM --- R/type.R | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/R/type.R b/R/type.R index 34ab1dfc..371fed06 100644 --- a/R/type.R +++ b/R/type.R @@ -5,7 +5,7 @@ #' '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 and it isn't identifed as a timing variable, it is assumed to be numeric and coerced with `as.numeric`. +#' 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 @@ -13,10 +13,6 @@ #' using a date class. For this reason, `xportr` will try to determine what #' should happen with variables that appear to be used to denote time. #' -#' For variables that end in DT, DTM, or, TM, if they are not explicitly noted -#' in 'xportr.numeric_types' or 'xportr.character_types', they are coerced to -#' numeric results. -#' #' @inheritParams xportr_length #' #' @section Messaging: `type_log()` is the primary messaging tool for From 7ec86fb450f2fddcc14ea033cf55120937819c43 Mon Sep 17 00:00:00 2001 From: Celine Date: Wed, 17 Jan 2024 05:58:00 -0500 Subject: [PATCH 06/17] Added Changes Description --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index 0adb7867..9151fb6b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,8 @@ * Added a check for character variable lengths up to 200 bytes in `xpt_validate()`(#91, #189). +* Added xportr.character_metadata_types and xportr.numeric_metadata_types so that all R types, including dates, are handled by xportr_type. In case the R type is different from the metadata type, the variable is coerced (#161). + ## Deprecation and Breaking Changes * The `label` argument from the `xportr_write()` function is deprecated in favor of the `metadata` argument. (#179) From c2c24bf423fae29856f5d63b1b27f664af2aa8c6 Mon Sep 17 00:00:00 2001 From: Celine Date: Wed, 17 Jan 2024 05:59:43 -0500 Subject: [PATCH 07/17] Updated function description --- man/xportr_type.Rd | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/man/xportr_type.Rd b/man/xportr_type.Rd index 1a49735b..f9fdab8a 100644 --- a/man/xportr_type.Rd +++ b/man/xportr_type.Rd @@ -38,7 +38,7 @@ 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 and it isn't identifed as a timing variable, it is assumed to be numeric and coerced with \code{as.numeric}. +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 @@ -46,10 +46,6 @@ based on a reference date of 01/01/1970 where XPT uses 01/01/1960. This can result in dates being 10 years off when outputting from R to XPT if you're using a date class. For this reason, \code{xportr} will try to determine what should happen with variables that appear to be used to denote time. - -For variables that end in DT, DTM, or, TM, if they are not explicitly noted -in 'xportr.numeric_types' or 'xportr.character_types', they are coerced to -numeric results. } \section{Messaging}{ \code{type_log()} is the primary messaging tool for From b96350ccaea88a33dcafaed37a70905af1c2128d Mon Sep 17 00:00:00 2001 From: Celine Date: Wed, 17 Jan 2024 06:28:28 -0500 Subject: [PATCH 08/17] fixed small bug --- tests/testthat/test-type.R | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/testthat/test-type.R b/tests/testthat/test-type.R index 45a3167d..d35207ed 100644 --- a/tests/testthat/test-type.R +++ b/tests/testthat/test-type.R @@ -339,6 +339,7 @@ test_that("xportr_metadata: Var date types (--DTC) coerced as expected and raise STUDYID = "character", USUBJID = "character", TRTEDT = "Date", EXSTDTC = "character" )) +}) test_that("xportr_type: Works as expected with only one domain in metadata", { adsl <- data.frame( From b24ae2506466a79d0b784257d7ccf126f5574033 Mon Sep 17 00:00:00 2001 From: Celine Date: Wed, 17 Jan 2024 06:29:40 -0500 Subject: [PATCH 09/17] Removed blank lines --- tests/testthat/test-type.R | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/testthat/test-type.R b/tests/testthat/test-type.R index d35207ed..dca4bc46 100644 --- a/tests/testthat/test-type.R +++ b/tests/testthat/test-type.R @@ -305,8 +305,6 @@ test_that("xportr_type: Drops factor levels", { expect_null(attributes(df2$Val)) }) - - df <- data.frame( STUDYID = c("PILOT01", "PILOT01", "PILOT01"), USUBJID = c("01-1130", "01-1133", "01-1133"), From fbf7839eede79bd65b90e47e7c34f993562360f1 Mon Sep 17 00:00:00 2001 From: Celine Date: Wed, 17 Jan 2024 06:35:46 -0500 Subject: [PATCH 10/17] Removed blank line --- tests/testthat/test-type.R | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/testthat/test-type.R b/tests/testthat/test-type.R index dca4bc46..244a85f0 100644 --- a/tests/testthat/test-type.R +++ b/tests/testthat/test-type.R @@ -353,5 +353,4 @@ test_that("xportr_type: Works as expected with only one domain in metadata", { ) expect_equal(xportr_type(adsl, metadata), adsl) - }) From e93b119aa73f2330f559c39e011b6bc9a7e61924 Mon Sep 17 00:00:00 2001 From: vedhav Date: Thu, 18 Jan 2024 01:15:06 +0530 Subject: [PATCH 11/17] chore: update docs with new options --- R/options.R | 8 ++++++-- R/xportr-package.R | 11 +++++++++-- R/zzz.R | 12 +++++++++--- man/xportr-package.Rd | 11 +++++++++-- man/xportr_options.Rd | 10 +++++++--- man/xportr_options_list.Rd | 2 +- 6 files changed, 41 insertions(+), 13 deletions(-) diff --git a/R/options.R b/R/options.R index 68d66943..4ad5280a 100644 --- a/R/options.R +++ b/R/options.R @@ -41,11 +41,15 @@ #' 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 `c("character", "char", "text", "date", "posixct", "posixt", +#' \item{xportr.character_types}{defaults to `"character"`}: +#' 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_types}{defaults to `c("integer", "numeric", "num", "float")`}: +#' \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", "posixct", "posixt", "time", "date")`}: #' The default character vector used to explicitly coerce R classes to numeric XPT types. #' } #' diff --git a/R/xportr-package.R b/R/xportr-package.R index 52098b45..906a00f7 100644 --- a/R/xportr-package.R +++ b/R/xportr-package.R @@ -64,15 +64,22 @@ #' } #' \item{ #' xportr.character_types - The default character vector used to explicitly +#' 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", #' "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") +#' } +#' \item{ #' xportr.numeric_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", "float", "posixct", "posixt", "time", "date") #' } #' } #' diff --git a/R/zzz.R b/R/zzz.R index 96033406..e72972d3 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -16,7 +16,7 @@ xportr_options_list <- list( xportr.label_verbose = getOption("xportr.label_verbose", "none"), xportr.length_verbose = getOption("xportr.length_verbose", "none"), xportr.type_verbose = getOption("xportr.type_verbose", "none"), - xportr.character_types = c("character"), + xportr.character_types = getOption("xportr.character_types", "character"), xportr.character_metadata_types = getOption( "xportr.character_types", c( @@ -27,8 +27,14 @@ xportr_options_list <- list( "intervaldatetime" ) ), - xportr.numeric_metadata_types = c("integer", "numeric", "num", "float"), - xportr.numeric_types = c("integer", "float", "posixct", "posixt", "time", "date") + xportr.numeric_metadata_types = getOption( + "xportr.numeric_metadata_types", + c("integer", "numeric", "num", "float") + ), + xportr.numeric_types = getOption( + "xportr.numeric_types", + c("integer", "float", "posixct", "posixt", "time", "date") + ) ) .onLoad <- function(libname, pkgname) { diff --git a/man/xportr-package.Rd b/man/xportr-package.Rd index e23a276c..3b7d8a63 100644 --- a/man/xportr-package.Rd +++ b/man/xportr-package.Rd @@ -71,15 +71,22 @@ xportr.type_verbose - The default argument for the 'verbose' argument for } \item{ xportr.character_types - The default character vector used to explicitly +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", "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") +} +\item{ xportr.numeric_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", "float", "posixct", "posixt", "time", "date") } } } diff --git a/man/xportr_options.Rd b/man/xportr_options.Rd index 4194aa52..db020a29 100644 --- a/man/xportr_options.Rd +++ b/man/xportr_options.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/options.R \name{xportr_options} \alias{xportr_options} -\title{Get or set Xportr options} +\title{Get or set xportr options} \usage{ xportr_options(...) } @@ -49,9 +49,13 @@ The default argument for the 'verbose' argument for \code{xportr_label}. 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{c("character", "char", "text", "date", "posixct", "posixt", "datetime", "time", "partialdate", "partialtime", "partialdatetime", "incompletedatetime", "durationdatetime", "intervaldatetime")}}: +\item{xportr.character_types}{defaults to \code{"character"}}: The default character vector used to explicitly coerce R classes to character XPT types. -\item{xportr.numeric_types}{defaults to \code{c("integer", "numeric", "num", "float")}}: +\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", "posixct", "posixt", "time", "date")}}: The default character vector used to explicitly coerce R classes to numeric XPT types. } } diff --git a/man/xportr_options_list.Rd b/man/xportr_options_list.Rd index fb36fa78..7717def3 100644 --- a/man/xportr_options_list.Rd +++ b/man/xportr_options_list.Rd @@ -5,7 +5,7 @@ \alias{xportr_options_list} \title{A list with all the supported options of xportr} \format{ -An object of class \code{list} of length 15. +An object of class \code{list} of length 17. } \usage{ xportr_options_list From 04f8fca2d24fb5b5debea0619fbbedace20706ba Mon Sep 17 00:00:00 2001 From: Celine Piraux <69685640+cpiraux@users.noreply.github.com> Date: Mon, 22 Jan 2024 13:20:07 +0100 Subject: [PATCH 12/17] Update description in type.R Co-authored-by: Ben Straub --- R/type.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/type.R b/R/type.R index e0cbe9e2..2a1bd3ef 100644 --- a/R/type.R +++ b/R/type.R @@ -5,7 +5,7 @@ #' '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`. +#' 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 From 701fb5e0a39ca0eb59894df9eda8e30d399eb386 Mon Sep 17 00:00:00 2001 From: Celine Date: Mon, 22 Jan 2024 07:31:45 -0500 Subject: [PATCH 13/17] Update option character_metadata_types --- R/zzz.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/zzz.R b/R/zzz.R index e72972d3..d986c442 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -18,7 +18,7 @@ xportr_options_list <- list( xportr.type_verbose = getOption("xportr.type_verbose", "none"), xportr.character_types = getOption("xportr.character_types", "character"), xportr.character_metadata_types = getOption( - "xportr.character_types", + "xportr.character_metadata_types", c( "character", "char", "text", "date", "posixct", "posixt", "datetime", "time", "partialdate", From be591a08e5f748ab3e97c822f1def584e21b4405 Mon Sep 17 00:00:00 2001 From: Celine Date: Mon, 22 Jan 2024 07:42:16 -0500 Subject: [PATCH 14/17] update description in NEWS.md --- NEWS.md | 3 +-- man/xportr_type.Rd | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index c118106b..9d3430df 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,8 +7,7 @@ * Added a check for character variable lengths up to 200 bytes in `xpt_validate()`(#91, #189). * File name check is moved to strict_checks condition to allow underscores in the file name. Underscores are allowed in xpt but not per FDA requirements. (#126) * It is now possible to get and set the xportr options using the helper function `xportr_options()` (#130) - -* Added xportr.character_metadata_types and xportr.numeric_metadata_types so that all R types, including dates, are handled by xportr_type. In case the R type is different from the metadata type, the variable is coerced (#161). +* Added `xportr.character_metadata_types` and `xportr.numeric_metadata_types` to list the metadata types that are character or numeric. Updated `xportr.character_types` and `xportr.numeric_types` to list only the R types that are character and the R types that are numeric. This ensures that all R types, including dates, are now managed by xportr_type. If the R type differs from the metadata type, the variable is coerced (#161).. ## Deprecation and Breaking Changes diff --git a/man/xportr_type.Rd b/man/xportr_type.Rd index 9f2ee549..c5d9b077 100644 --- a/man/xportr_type.Rd +++ b/man/xportr_type.Rd @@ -38,7 +38,7 @@ 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}. +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 From 2d5fe41b75dec9fe35da3d3608115306bcff4a10 Mon Sep 17 00:00:00 2001 From: vedhav Date: Thu, 1 Feb 2024 19:49:24 +0530 Subject: [PATCH 15/17] fix: pass the domain name explicitly --- R/support-test.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/support-test.R b/R/support-test.R index d223a6d6..fa9cb048 100644 --- a/R/support-test.R +++ b/R/support-test.R @@ -152,7 +152,7 @@ multiple_vars_in_spec_helper <- function(FUN) { local_cli_theme() adsl %>% - FUN(metadata) %>% + FUN(metadata, "adsl") %>% testthat::expect_message("There are multiple specs for the same variable name") } @@ -181,6 +181,6 @@ multiple_vars_in_spec_helper2 <- function(FUN) { adsl %>% xportr_metadata(domain = "adsl") %>% - FUN(metadata) %>% + FUN(metadata, "adsl") %>% testthat::expect_no_message(message = "There are multiple specs for the same variable name") } From 7c1ccde1ebde7f1a5e5d0a45a1ebc7d68a86ca88 Mon Sep 17 00:00:00 2001 From: Celine Date: Mon, 5 Feb 2024 10:16:04 -0500 Subject: [PATCH 16/17] Add numeric to R numeric type --- R/options.R | 2 +- R/xportr-package.R | 2 +- R/zzz.R | 2 +- man/xportr-package.Rd | 4 ++-- man/xportr_options.Rd | 2 +- man/xportr_type.Rd | 9 +++++++-- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/R/options.R b/R/options.R index 4ad5280a..c27628fa 100644 --- a/R/options.R +++ b/R/options.R @@ -49,7 +49,7 @@ #' 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", "posixct", "posixt", "time", "date")`}: +#' \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. #' } #' diff --git a/R/xportr-package.R b/R/xportr-package.R index 60b3277a..19072ba2 100644 --- a/R/xportr-package.R +++ b/R/xportr-package.R @@ -79,7 +79,7 @@ #' } #' \item{ #' xportr.numeric_types - The default character vector used to explicitly -#' coerce R classes to numeric XPT types. Default: c("integer", "float", "posixct", "posixt", "time", "date") +#' coerce R classes to numeric XPT types. Default: c("integer", "float", "numeric", "posixct", "posixt", "time", "date") #' } #' } #' diff --git a/R/zzz.R b/R/zzz.R index d986c442..db793471 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", "posixct", "posixt", "time", "date") + c("integer", "float", "numeric", "posixct", "posixt", "time", "date") ) ) diff --git a/man/xportr-package.Rd b/man/xportr-package.Rd index d70cc8bd..762cab17 100644 --- a/man/xportr-package.Rd +++ b/man/xportr-package.Rd @@ -78,7 +78,7 @@ xportr.character_metadata_types - The default character vector used to explicitl coerce R classes to character XPT types. Default: c("character", "char", "text", "date", "posixct", "posixt", "datetime", "time", "partialdate", "partialtime", "partialdatetime", "incompletedatetime", "durationdatetime", -"intervaldatetime") +"intervaldatetime")` } \item{ xportr.numeric_metadata_types - The default character vector used to explicitly @@ -86,7 +86,7 @@ coerce R classes to numeric XPT types. Default: c("integer", "numeric", "num", " } \item{ xportr.numeric_types - The default character vector used to explicitly -coerce R classes to numeric XPT types. Default: c("integer", "float", "posixct", "posixt", "time", "date") +coerce R classes to numeric XPT types. Default: c("integer", "float", "numeric", "posixct", "posixt", "time", "date") } } } diff --git a/man/xportr_options.Rd b/man/xportr_options.Rd index db020a29..9c07d0ad 100644 --- a/man/xportr_options.Rd +++ b/man/xportr_options.Rd @@ -55,7 +55,7 @@ The default character vector used to explicitly coerce R classes to character XP 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", "posixct", "posixt", "time", "date")}}: +\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. } } diff --git a/man/xportr_type.Rd b/man/xportr_type.Rd index 515f4bd0..df1a6b6c 100644 --- a/man/xportr_type.Rd +++ b/man/xportr_type.Rd @@ -39,6 +39,7 @@ attempts to collapse R classes to those two XPT types. The 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()}. +} \details{ 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 @@ -71,9 +72,13 @@ metadata. \item Variable Type - passed as the 'xportr.type_name'. Default: "type". This is used to note the XPT variable "type" options are numeric or character. \item (Option only) Character Types - The list of classes that should be -explicitly coerced to a XPT Character type. Default: \code{c( "character", "char", "text", "date", "posixct", "posixt", "datetime", "time", "partialdate", "partialtime", "partialdatetime", "incompletedatetime", "durationdatetime", "intervaldatetime")} +explicitly coerced to a XPT Character type. Default: c( "character", +"char", "text", "date", "posixct", "posixt", "datetime", "time", +"partialdate", "partialtime", "partialdatetime", "incompletedatetime", +"durationdatetime", "intervaldatetime")` \item (Option only) Numeric Types - The list of classes that should be -explicitly coerced to a XPT numeric type. Default: \code{c("integer", "numeric", "num", "float")} +explicitly coerced to a XPT numeric type. Default: c("integer", "numeric", +"num", "float") } } From 388223ce780b128ad3c32a6a34dac200a031f7e9 Mon Sep 17 00:00:00 2001 From: Celine Date: Mon, 5 Feb 2024 10:30:53 -0500 Subject: [PATCH 17/17] Split too long line --- R/xportr-package.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/xportr-package.R b/R/xportr-package.R index 19072ba2..4200890b 100644 --- a/R/xportr-package.R +++ b/R/xportr-package.R @@ -79,7 +79,8 @@ #' } #' \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: c("integer", "float", +#' "numeric", "posixct", "posixt", "time", "date") #' } #' } #'