From 63c5b7b1ff56a6b7a7bad0b1f6fa2f621af3357c Mon Sep 17 00:00:00 2001 From: EeethB Date: Mon, 8 Jan 2024 16:23:38 -0600 Subject: [PATCH 01/26] Add `verbose` option to metadata --- R/metadata.R | 11 ++++++++--- man/metadata.Rd | 11 ++++++++++- tests/testthat/test-metadata.R | 32 +++++++++++++++----------------- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/R/metadata.R b/R/metadata.R index 2db7d1b5..4da01a30 100644 --- a/R/metadata.R +++ b/R/metadata.R @@ -40,15 +40,20 @@ #' xportr_type() %>% #' xportr_order() #' } -xportr_metadata <- function(.df, metadata, domain = NULL) { - ## Common section to detect domain from argument or attribute +xportr_metadata <- function(.df, + metadata, + domain = NULL, + verbose = getOption("xportr.type_verbose", "none")) { + ## Common section to detect domain from argument or pipes domain <- get_domain(.df, domain) if (!is.null(domain)) attr(.df, "_xportr.df_arg_") <- domain ## End of common section - structure(.df, `_xportr.df_metadata_` = metadata) + structure(.df, + `_xportr.df_metadata_` = metadata, + `_xportr.df_verbose_` = verbose) } diff --git a/man/metadata.Rd b/man/metadata.Rd index f3c497de..a74613a6 100644 --- a/man/metadata.Rd +++ b/man/metadata.Rd @@ -5,7 +5,12 @@ \alias{xportr_domain_name} \title{Set variable specifications and domain} \usage{ -xportr_metadata(.df, metadata, domain = NULL) +xportr_metadata( + .df, + metadata, + domain = NULL, + verbose = getOption("xportr.type_verbose", "none") +) xportr_domain_name(.df, domain) } @@ -19,6 +24,10 @@ xportr_domain_name(.df, domain) the metadata object. If none is passed, then \code{\link[=xportr_domain_name]{xportr_domain_name()}} or \code{\link[=xportr_metadata]{xportr_metadata()}} must be called before hand to set the domain as an attribute of \code{.df}.} + +\item{verbose}{The action this function takes when an action is taken on the +dataset or function validation finds an issue. See 'Messaging' section for +details. Options are 'stop', 'warn', 'message', and 'none'} } \value{ \code{.df} dataset with metadata and domain attributes set diff --git a/tests/testthat/test-metadata.R b/tests/testthat/test-metadata.R index b3041018..6f7ec281 100644 --- a/tests/testthat/test-metadata.R +++ b/tests/testthat/test-metadata.R @@ -560,47 +560,45 @@ test_that("xportr_metadata: Check metadata interaction with other functions", { rlang::set_names(tolower) expect_equal( - structure(xportr_type(adsl, var_spec, domain = "adsl"), `_xportr.df_metadata_` = var_spec), + structure(xportr_type(adsl, var_spec, domain = "adsl"), + `_xportr.df_metadata_` = var_spec, + `_xportr.df_verbose_` = "none"), suppressMessages( xportr_metadata(adsl, var_spec, domain = "adsl") %>% xportr_type() ) ) expect_equal( - structure( - suppressMessages(xportr_length(adsl, var_spec, domain = "adsl")), - `_xportr.df_metadata_` = var_spec - ), + structure(xportr_length(adsl, var_spec, domain = "adsl"), + `_xportr.df_metadata_` = var_spec, + `_xportr.df_verbose_` = "none"), suppressMessages( xportr_metadata(adsl, var_spec, domain = "adsl") %>% xportr_length() ) ) expect_equal( - structure( - suppressMessages(xportr_label(adsl, var_spec, domain = "adsl")), - `_xportr.df_metadata_` = var_spec - ), + structure(xportr_label(adsl, var_spec, domain = "adsl"), + `_xportr.df_metadata_` = var_spec, + `_xportr.df_verbose_` = "none"), suppressMessages( xportr_metadata(adsl, var_spec, domain = "adsl") %>% xportr_label() ) ) expect_equal( - structure( - suppressMessages(xportr_order(adsl, var_spec, domain = "adsl")), - `_xportr.df_metadata_` = var_spec - ), + structure(xportr_order(adsl, var_spec, domain = "adsl"), + `_xportr.df_metadata_` = var_spec, + `_xportr.df_verbose_` = "none"), suppressMessages( xportr_metadata(adsl, var_spec, domain = "adsl") %>% xportr_order() ) ) expect_equal( - structure( - suppressMessages(xportr_format(adsl, var_spec, domain = "adsl")), - `_xportr.df_metadata_` = var_spec - ), + structure(xportr_format(adsl, var_spec, domain = "adsl"), + `_xportr.df_metadata_` = var_spec, + `_xportr.df_verbose_` = "none"), suppressMessages( xportr_metadata(adsl, var_spec, domain = "adsl") %>% xportr_format() ) From 18c766fb2d19a7e839ec37aa2c5da85571499867 Mon Sep 17 00:00:00 2001 From: EeethB Date: Tue, 28 Nov 2023 16:09:20 +0000 Subject: [PATCH 02/26] Add verbose to metadata --- R/label.R | 8 +++++++- R/length.R | 8 +++++++- R/metadata.R | 2 +- R/order.R | 8 +++++++- R/type.R | 8 +++++++- man/metadata.Rd | 7 +------ man/xportr_label.Rd | 2 +- man/xportr_length.Rd | 2 +- man/xportr_order.Rd | 2 +- man/xportr_type.Rd | 2 +- tests/testthat/test-length.R | 13 +++++++++++++ tests/testthat/test-order.R | 13 +++++++++++++ tests/testthat/test-type.R | 20 ++++++++++++++++---- 13 files changed, 76 insertions(+), 19 deletions(-) diff --git a/R/label.R b/R/label.R index 6724e53d..de0630ad 100644 --- a/R/label.R +++ b/R/label.R @@ -59,7 +59,7 @@ xportr_label <- function(.df, metadata = NULL, domain = NULL, - verbose = getOption("xportr.label_verbose", "none"), + verbose = NULL, metacore = deprecated()) { if (!missing(metacore)) { lifecycle::deprecate_stop( @@ -99,6 +99,12 @@ xportr_label <- function(.df, # Check any variables missed in metadata but present in input data --- miss_vars <- setdiff(names(.df), metadata[[variable_name]]) + # Verbose should use an explicit verbose option first, then the value set in + # metadata, and finally fall back to the option value + verbose <- verbose %||% + attr(.df, "_xportr.df_verbose_") %||% + getOption("xportr.label_verbose", "none") + label_log(miss_vars, verbose) label <- metadata[[variable_label]] diff --git a/R/length.R b/R/length.R index 3039218f..076bfc56 100644 --- a/R/length.R +++ b/R/length.R @@ -67,7 +67,7 @@ xportr_length <- function(.df, metadata = NULL, domain = NULL, - verbose = getOption("xportr.length_verbose", "none"), + verbose = NULL, metacore = deprecated()) { if (!missing(metacore)) { lifecycle::deprecate_stop( @@ -107,6 +107,12 @@ xportr_length <- function(.df, # Check any variables missed in metadata but present in input data --- miss_vars <- setdiff(names(.df), metadata[[variable_name]]) + # Verbose should use an explicit verbose option first, then the value set in + # metadata, and finally fall back to the option value + verbose <- verbose %||% + attr(.df, "_xportr.df_verbose_") %||% + getOption("xportr.length_verbose", "none") + length_log(miss_vars, verbose) length <- metadata[[variable_length]] diff --git a/R/metadata.R b/R/metadata.R index 4da01a30..bf1e616d 100644 --- a/R/metadata.R +++ b/R/metadata.R @@ -43,7 +43,7 @@ xportr_metadata <- function(.df, metadata, domain = NULL, - verbose = getOption("xportr.type_verbose", "none")) { + verbose = NULL) { ## Common section to detect domain from argument or pipes domain <- get_domain(.df, domain) diff --git a/R/order.R b/R/order.R index 60bccbc8..1358a877 100644 --- a/R/order.R +++ b/R/order.R @@ -62,7 +62,7 @@ xportr_order <- function(.df, metadata = NULL, domain = NULL, - verbose = getOption("xportr.order_verbose", "none"), + verbose = NULL, metacore = deprecated()) { if (!missing(metacore)) { lifecycle::deprecate_stop( @@ -120,6 +120,12 @@ xportr_order <- function(.df, # Used in warning message for how many vars have been moved reorder_vars <- names(df_re_ord)[names(df_re_ord) != names(.df)] + # Verbose should use an explicit verbose option first, then the value set in + # metadata, and finally fall back to the option value + verbose <- verbose %||% + attr(.df, "_xportr.df_verbose_") %||% + getOption("xportr.order_verbose", "none") + # Function is located in messages.R var_ord_msg(reorder_vars, names(drop_vars), verbose) diff --git a/R/type.R b/R/type.R index 8f45e326..8441c7c4 100644 --- a/R/type.R +++ b/R/type.R @@ -79,7 +79,7 @@ xportr_type <- function(.df, metadata = NULL, domain = NULL, - verbose = getOption("xportr.type_verbose", "none"), + verbose = NULL, metacore = deprecated()) { if (!missing(metacore)) { lifecycle::deprecate_stop( @@ -146,6 +146,12 @@ xportr_type <- function(.df, type.y = if_else(type.y %in% numericTypes, "_numeric", type.y) ) + # Verbose should use an explicit verbose option first, then the value set in + # metadata, and finally fall back to the option value + verbose <- verbose %||% + attr(.df, "_xportr.df_verbose_") %||% + getOption("xportr.type_verbose", "none") + # It is possible that a variable exists in the table that isn't in the metadata # it will be silently ignored here. This may happen depending on what a user # passes and the options they choose. The check_core function is the place diff --git a/man/metadata.Rd b/man/metadata.Rd index a74613a6..4c52c4ea 100644 --- a/man/metadata.Rd +++ b/man/metadata.Rd @@ -5,12 +5,7 @@ \alias{xportr_domain_name} \title{Set variable specifications and domain} \usage{ -xportr_metadata( - .df, - metadata, - domain = NULL, - verbose = getOption("xportr.type_verbose", "none") -) +xportr_metadata(.df, metadata, domain = NULL, verbose = NULL) xportr_domain_name(.df, domain) } diff --git a/man/xportr_label.Rd b/man/xportr_label.Rd index 87d648da..7f447418 100644 --- a/man/xportr_label.Rd +++ b/man/xportr_label.Rd @@ -8,7 +8,7 @@ xportr_label( .df, metadata = NULL, domain = NULL, - verbose = getOption("xportr.label_verbose", "none"), + verbose = NULL, metacore = deprecated() ) } diff --git a/man/xportr_length.Rd b/man/xportr_length.Rd index 1d5100df..fa51508e 100644 --- a/man/xportr_length.Rd +++ b/man/xportr_length.Rd @@ -8,7 +8,7 @@ xportr_length( .df, metadata = NULL, domain = NULL, - verbose = getOption("xportr.length_verbose", "none"), + verbose = NULL, metacore = deprecated() ) } diff --git a/man/xportr_order.Rd b/man/xportr_order.Rd index 72bda30d..bf20ffa7 100644 --- a/man/xportr_order.Rd +++ b/man/xportr_order.Rd @@ -8,7 +8,7 @@ xportr_order( .df, metadata = NULL, domain = NULL, - verbose = getOption("xportr.order_verbose", "none"), + verbose = NULL, metacore = deprecated() ) } diff --git a/man/xportr_type.Rd b/man/xportr_type.Rd index 3c67c4c7..6c4486ad 100644 --- a/man/xportr_type.Rd +++ b/man/xportr_type.Rd @@ -8,7 +8,7 @@ xportr_type( .df, metadata = NULL, domain = NULL, - verbose = getOption("xportr.type_verbose", "none"), + verbose = NULL, metacore = deprecated() ) } diff --git a/tests/testthat/test-length.R b/tests/testthat/test-length.R index 7fa87f53..7ca82e87 100644 --- a/tests/testthat/test-length.R +++ b/tests/testthat/test-length.R @@ -97,6 +97,13 @@ test_that("xportr_length: Impute character lengths based on class", { expect_message("Variable lengths missing from metadata") %>% expect_message("lengths resolved") %>% expect_attr_width(c(7, 199, 200, 200, 8)) + + adsl %>% + xportr_metadata(metadata, verbose = "none") %>% + xportr_length() %>% + expect_message("Variable lengths missing from metadata") %>% + expect_message("lengths resolved") %>% + expect_attr_width(c(7, 199, 200, 200, 8)) }) test_that("xportr_length: Throws message when variables not present in metadata", { @@ -113,6 +120,12 @@ test_that("xportr_length: Throws message when variables not present in metadata" expect_message("Variable lengths missing from metadata") %>% expect_message("lengths resolved") %>% expect_message(regexp = "Problem with `y`") + + xportr_metadata(adsl, metadata, verbose = "message") %>% + xportr_length() %>% + expect_message("Variable lengths missing from metadata") %>% + expect_message("lengths resolved") %>% + expect_message(regexp = "Problem with `y`") }) test_that("xportr_length: Metacore instance can be used", { diff --git a/tests/testthat/test-order.R b/tests/testthat/test-order.R index 3450ba10..59c3044c 100644 --- a/tests/testthat/test-order.R +++ b/tests/testthat/test-order.R @@ -136,6 +136,19 @@ test_that("xportr_order: Variable ordering messaging is correct", { expect_message("2 variables not in spec and moved to end") %>% expect_message("Variable moved to end in `.df`: `a` and `z`") %>% expect_message("All variables in dataset are ordered") + + # Metadata versions + xportr_metadata(df, df_meta, verbose = "message") %>% + xportr_order() %>% + expect_message("All variables in specification file are in dataset") %>% + expect_condition("4 reordered in dataset") %>% + expect_message("Variable reordered in `.df`: `a`, `b`, `c`, and `d`") + + xportr_metadata(df2, df_meta, verbose = "message") %>% + xportr_order() %>% + expect_message("2 variables not in spec and moved to end") %>% + expect_message("Variable moved to end in `.df`: `a` and `z`") %>% + expect_message("All variables in dataset are ordered") }) test_that("xportr_order: Metadata order columns are coersed to numeric", { diff --git a/tests/testthat/test-type.R b/tests/testthat/test-type.R index f53271cc..d4bba61f 100644 --- a/tests/testthat/test-type.R +++ b/tests/testthat/test-type.R @@ -66,6 +66,12 @@ test_that("xportr_type: Variable types are coerced as expected and can raise mes (df3 <- suppressMessages(xportr_type(df, meta_example, verbose = "warn", domain = "df"))) %>% expect_warning() + # Metadata version of the last statement + df %>% + xportr_metadata(meta_example, verbose = "warn") %>% + xportr_type() %>% + expect_warning() + expect_equal(purrr::map_chr(df3, class), c( Subj = "numeric", Different = "character", Val = "numeric", Param = "character" @@ -77,6 +83,12 @@ test_that("xportr_type: Variable types are coerced as expected and can raise mes expect_message("Variable type\\(s\\) in dataframe don't match metadata") ) + # Metadata version + df %>% + xportr_metadata(meta_example, verbose = "message") %>% + xportr_type() %>% + expect_message("Variable type\\(s\\) in dataframe don't match metadata") + expect_equal(purrr::map_chr(df4, class), c( Subj = "numeric", Different = "character", Val = "numeric", Param = "character" @@ -100,12 +112,12 @@ test_that("xportr_metadata: Var types coerced as expected and raise messages", { )) suppressMessages( - xportr_metadata(df, meta_example, domain = "df") %>% xportr_type(verbose = "stop") + xportr_metadata(df, meta_example, verbose = "stop") %>% xportr_type() ) %>% expect_error() suppressMessages( - df3 <- xportr_metadata(df, meta_example, domain = "df") %>% xportr_type(verbose = "warn") + df3 <- xportr_metadata(df, meta_example, verbose = "warn") %>% xportr_type() ) %>% expect_warning() @@ -116,8 +128,8 @@ test_that("xportr_metadata: Var types coerced as expected and raise messages", { suppressMessages({ ( - df4 <- xportr_metadata(df, meta_example, domain = "df") %>% - xportr_type(verbose = "message") + df4 <- xportr_metadata(df, meta_example, verbose = "message") %>% + xportr_type() ) %>% expect_message("Variable type\\(s\\) in dataframe don't match metadata: `Subj` and `Val`") }) From c96d4df651056e4b6159a1dfd4b1e6f83f78313f Mon Sep 17 00:00:00 2001 From: EeethB Date: Wed, 6 Dec 2023 22:24:17 +0000 Subject: [PATCH 03/26] Update docs --- NEWS.md | 6 +++ R/metadata.R | 5 +- README.Rmd | 2 +- tests/testthat/test-length.R | 13 ----- tests/testthat/test-metadata.R | 90 ++++++++++++++++++++++++++++++++++ tests/testthat/test-order.R | 13 ----- tests/testthat/test-type.R | 57 --------------------- 7 files changed, 100 insertions(+), 86 deletions(-) diff --git a/NEWS.md b/NEWS.md index 3a66b267..217c5099 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,12 @@ * Added a check for character variable lengths up to 200 bytes in `xpt_validate()`(#91, #189). +* `xportr_metadata()` can set `verbose` for a whole pipeline, i.e. setting `verbose` in `xportr_metadata()` will populate to all `xportr` functions. (#151) + +* All `xportr` functions now have `verbose = NULL` as the default. If left `NULL`, the previous default of `getOption("xportr.[fn_name]_verbose")` is used (#151) + +## Documentation + ## Deprecation and Breaking Changes * The `domain` argument for xportr functions will no longer be dynamically diff --git a/R/metadata.R b/R/metadata.R index bf1e616d..555407c5 100644 --- a/R/metadata.R +++ b/R/metadata.R @@ -52,8 +52,9 @@ xportr_metadata <- function(.df, ## End of common section structure(.df, - `_xportr.df_metadata_` = metadata, - `_xportr.df_verbose_` = verbose) + `_xportr.df_metadata_` = metadata, + `_xportr.df_verbose_` = verbose + ) } diff --git a/README.Rmd b/README.Rmd index 1541a21b..edc532c9 100644 --- a/README.Rmd +++ b/README.Rmd @@ -145,7 +145,7 @@ The `xportr_metadata()` function can reduce duplication by setting the variable ```{r, message=FALSE, eval=FALSE} adsl %>% - xportr_metadata(var_spec, "ADSL") %>% + xportr_metadata(var_spec, "ADSL", verbose = "warn") %>% xportr_type() %>% xportr_length() %>% xportr_label() %>% diff --git a/tests/testthat/test-length.R b/tests/testthat/test-length.R index 7ca82e87..7fa87f53 100644 --- a/tests/testthat/test-length.R +++ b/tests/testthat/test-length.R @@ -97,13 +97,6 @@ test_that("xportr_length: Impute character lengths based on class", { expect_message("Variable lengths missing from metadata") %>% expect_message("lengths resolved") %>% expect_attr_width(c(7, 199, 200, 200, 8)) - - adsl %>% - xportr_metadata(metadata, verbose = "none") %>% - xportr_length() %>% - expect_message("Variable lengths missing from metadata") %>% - expect_message("lengths resolved") %>% - expect_attr_width(c(7, 199, 200, 200, 8)) }) test_that("xportr_length: Throws message when variables not present in metadata", { @@ -120,12 +113,6 @@ test_that("xportr_length: Throws message when variables not present in metadata" expect_message("Variable lengths missing from metadata") %>% expect_message("lengths resolved") %>% expect_message(regexp = "Problem with `y`") - - xportr_metadata(adsl, metadata, verbose = "message") %>% - xportr_length() %>% - expect_message("Variable lengths missing from metadata") %>% - expect_message("lengths resolved") %>% - expect_message(regexp = "Problem with `y`") }) test_that("xportr_length: Metacore instance can be used", { diff --git a/tests/testthat/test-metadata.R b/tests/testthat/test-metadata.R index 6f7ec281..27b80500 100644 --- a/tests/testthat/test-metadata.R +++ b/tests/testthat/test-metadata.R @@ -544,6 +544,96 @@ test_that("xportr_length: Expect error if domain is not a character", { ) }) +test_that("xportr_metadata: Impute character lengths based on class", { + adsl <- minimal_table(30, cols = c("x", "b")) + metadata <- minimal_metadata( + dataset = TRUE, length = TRUE, var_names = colnames(adsl) + ) %>% + mutate(length = length - 1) + + adsl <- adsl %>% + mutate( + new_date = as.Date(.data$x, origin = "1970-01-01"), + new_char = as.character(.data$b), + new_num = as.numeric(.data$x) + ) + + adsl %>% + xportr_metadata(metadata, verbose = "none") %>% + xportr_length() %>% + expect_message("Variable lengths missing from metadata") %>% + expect_message("lengths resolved") %>% + expect_attr_width(c(7, 199, 200, 200, 8)) +}) + +test_that("xportr_metadata: Throws message when variables not present in metadata", { + adsl <- minimal_table(30, cols = c("x", "y")) + metadata <- minimal_metadata(dataset = TRUE, length = TRUE, var_names = c("x")) + + # Test that message is given which indicates that variable is not present + xportr_metadata(adsl, metadata, verbose = "message") %>% + xportr_length() %>% + expect_message("Variable lengths missing from metadata") %>% + expect_message("lengths resolved") %>% + expect_message(regexp = "Problem with `y`") +}) + +test_that("xportr_metadata: Variable ordering messaging is correct", { + skip_if_not_installed("haven") + skip_if_not_installed("readxl") + + require(haven, quietly = TRUE) + require(readxl, quietly = TRUE) + + df <- data.frame(c = 1:5, a = "a", d = 5:1, b = LETTERS[1:5]) + df2 <- data.frame(a = "a", z = "z") + df_meta <- data.frame( + dataset = "df", + variable = letters[1:4], + order = 1:4 + ) + + # Metadata versions + xportr_metadata(df, df_meta, verbose = "message") %>% + xportr_order() %>% + expect_message("All variables in specification file are in dataset") %>% + expect_condition("4 reordered in dataset") %>% + expect_message("Variable reordered in `.df`: `a`, `b`, `c`, and `d`") + + xportr_metadata(df2, df_meta, verbose = "message") %>% + xportr_order() %>% + expect_message("2 variables not in spec and moved to end") %>% + expect_message("Variable moved to end in `.df`: `a` and `z`") %>% + expect_message("All variables in dataset are ordered") +}) + +test_that("xportr_type: Variable types are coerced as expected and can raise messages", { + df <- data.frame( + Subj = as.character(c(123, 456, 789, "", NA, NA_integer_)), + Different = c("a", "b", "c", "", NA, NA_character_), + Val = c("1", "2", "3", "", NA, NA_character_), + Param = c("param1", "param2", "param3", "", NA, NA_character_) + ) + meta_example <- data.frame( + dataset = "df", + variable = c("Subj", "Param", "Val", "NotUsed"), + type = c("numeric", "character", "numeric", "character"), + format = NA + ) + + # Metadata version of the last statement + df %>% + xportr_metadata(meta_example, verbose = "warn") %>% + xportr_type() %>% + expect_warning() + + # Metadata version + df %>% + xportr_metadata(meta_example, verbose = "message") %>% + xportr_type() %>% + expect_message("Variable type\\(s\\) in dataframe don't match metadata") +}) + # many tests here are more like qualification/domain testing - this section adds # tests for `xportr_metadata()` basic functionality # start diff --git a/tests/testthat/test-order.R b/tests/testthat/test-order.R index 59c3044c..3450ba10 100644 --- a/tests/testthat/test-order.R +++ b/tests/testthat/test-order.R @@ -136,19 +136,6 @@ test_that("xportr_order: Variable ordering messaging is correct", { expect_message("2 variables not in spec and moved to end") %>% expect_message("Variable moved to end in `.df`: `a` and `z`") %>% expect_message("All variables in dataset are ordered") - - # Metadata versions - xportr_metadata(df, df_meta, verbose = "message") %>% - xportr_order() %>% - expect_message("All variables in specification file are in dataset") %>% - expect_condition("4 reordered in dataset") %>% - expect_message("Variable reordered in `.df`: `a`, `b`, `c`, and `d`") - - xportr_metadata(df2, df_meta, verbose = "message") %>% - xportr_order() %>% - expect_message("2 variables not in spec and moved to end") %>% - expect_message("Variable moved to end in `.df`: `a` and `z`") %>% - expect_message("All variables in dataset are ordered") }) test_that("xportr_order: Metadata order columns are coersed to numeric", { diff --git a/tests/testthat/test-type.R b/tests/testthat/test-type.R index d4bba61f..3fa7dd15 100644 --- a/tests/testthat/test-type.R +++ b/tests/testthat/test-type.R @@ -66,12 +66,6 @@ test_that("xportr_type: Variable types are coerced as expected and can raise mes (df3 <- suppressMessages(xportr_type(df, meta_example, verbose = "warn", domain = "df"))) %>% expect_warning() - # Metadata version of the last statement - df %>% - xportr_metadata(meta_example, verbose = "warn") %>% - xportr_type() %>% - expect_warning() - expect_equal(purrr::map_chr(df3, class), c( Subj = "numeric", Different = "character", Val = "numeric", Param = "character" @@ -83,57 +77,6 @@ test_that("xportr_type: Variable types are coerced as expected and can raise mes expect_message("Variable type\\(s\\) in dataframe don't match metadata") ) - # Metadata version - df %>% - xportr_metadata(meta_example, verbose = "message") %>% - xportr_type() %>% - expect_message("Variable type\\(s\\) in dataframe don't match metadata") - - expect_equal(purrr::map_chr(df4, class), c( - Subj = "numeric", Different = "character", - Val = "numeric", Param = "character" - )) -}) - -test_that("xportr_metadata: Var types coerced as expected and raise messages", { - # Remove empty lines in cli theme - local_cli_theme() - - ( - df2 <- xportr_metadata(df, meta_example, domain = "df") %>% - xportr_type() - ) %>% - expect_message("Variable type mismatches found.") %>% - expect_message("[0-9+] variables coerced") - - expect_equal(purrr::map_chr(df2, class), c( - Subj = "numeric", Different = "character", - Val = "numeric", Param = "character" - )) - - suppressMessages( - xportr_metadata(df, meta_example, verbose = "stop") %>% xportr_type() - ) %>% - expect_error() - - suppressMessages( - df3 <- xportr_metadata(df, meta_example, verbose = "warn") %>% xportr_type() - ) %>% - expect_warning() - - expect_equal(purrr::map_chr(df3, class), c( - Subj = "numeric", Different = "character", - Val = "numeric", Param = "character" - )) - - suppressMessages({ - ( - df4 <- xportr_metadata(df, meta_example, verbose = "message") %>% - xportr_type() - ) %>% - expect_message("Variable type\\(s\\) in dataframe don't match metadata: `Subj` and `Val`") - }) - expect_equal(purrr::map_chr(df4, class), c( Subj = "numeric", Different = "character", Val = "numeric", Param = "character" From f6a644b3a3679026bbebb232b25c3e12b58d6bf1 Mon Sep 17 00:00:00 2001 From: EeethB Date: Mon, 11 Dec 2023 18:19:55 +0000 Subject: [PATCH 04/26] Add basic top-level wrapper --- R/process.R | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 R/process.R diff --git a/R/process.R b/R/process.R new file mode 100644 index 00000000..0dd16c95 --- /dev/null +++ b/R/process.R @@ -0,0 +1,17 @@ +xportr_process <- function(.df, + metadata = NULL, + domain = NULL, + verbose = getOption("xportr.type_verbose", "none"), + path, + strict_checks = FALSE + ) { + .df %>% + xportr_metadata(metadata, domain) %>% + xportr_type() %>% + xportr_length() %>% + xportr_label() %>% + xportr_order() %>% + xportr_format() %>% + xportr_df_label(dataset_spec) %>% + xportr_write("adsl.xpt") +} From 21accf03b0a412d96af0d7ee6d9c187c62470551 Mon Sep 17 00:00:00 2001 From: EeethB Date: Mon, 8 Jan 2024 11:20:27 -0600 Subject: [PATCH 05/26] Add docs for xportr() --- NAMESPACE | 1 + R/process.R | 17 ----------- R/xportr.R | 75 ++++++++++++++++++++++++++++++++++++++++++++++ man/xportr.Rd | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 159 insertions(+), 17 deletions(-) delete mode 100644 R/process.R create mode 100644 R/xportr.R create mode 100644 man/xportr.Rd diff --git a/NAMESPACE b/NAMESPACE index dd495905..5a5d4df7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,6 +5,7 @@ export(length_log) export(type_log) export(var_names_log) export(var_ord_msg) +export(xportr) export(xportr_df_label) export(xportr_domain_name) export(xportr_format) diff --git a/R/process.R b/R/process.R deleted file mode 100644 index 0dd16c95..00000000 --- a/R/process.R +++ /dev/null @@ -1,17 +0,0 @@ -xportr_process <- function(.df, - metadata = NULL, - domain = NULL, - verbose = getOption("xportr.type_verbose", "none"), - path, - strict_checks = FALSE - ) { - .df %>% - xportr_metadata(metadata, domain) %>% - xportr_type() %>% - xportr_length() %>% - xportr_label() %>% - xportr_order() %>% - xportr_format() %>% - xportr_df_label(dataset_spec) %>% - xportr_write("adsl.xpt") -} diff --git a/R/xportr.R b/R/xportr.R new file mode 100644 index 00000000..687e66d6 --- /dev/null +++ b/R/xportr.R @@ -0,0 +1,75 @@ +#' Wrapper to apply all core xportr functions and write xpt +#' +#' @param .df A data frame of CDISC standard. +#' @param var_metadata A data frame containing variable level metadata +#' @param domain Appropriate CDSIC dataset name, e.g. ADAE, DM. Used to subset +#' the metadata object. If none is passed, then name of the dataset passed as +#' .df will be used. +#' @param verbose The action this function takes when an action is taken on the +#' dataset or function validation finds an issue. See 'Messaging' section for +#' details. Options are 'stop', 'warn', 'message', and 'none' +#' @param df_metadata A data frame containing dataset level metadata. +#' @param path Path where transport file will be written. File name sans will be +#' used as `xpt` name. +#' @param strict_checks If TRUE, xpt validation will report errors and not write +#' out the dataset. If FALSE, xpt validation will report warnings and continue +#' with writing out the dataset. Defaults to FALSE +#' +#' @return Returns the input dataframe invisibly +#' @export +#' +#' @examples +#' +#' has_pkgs <- require(admiral, quietly = TRUE) && +#' require(dplyr, quietly = TRUE) && +#' require(readxl, quietly = TRUE) && +#' require(rlang, quietly = TRUE) +#' +#' if (has_pkgs) { +#' adsl <- admiral::admiral_adsl +#' +#' spec_path <- system.file(paste0("specs/", "ADaM_admiral_spec.xlsx"), package = "xportr") +#' +#' var_spec <- readxl::read_xlsx(spec_path, sheet = "Variables") %>% +#' dplyr::rename(type = "Data Type") %>% +#' rlang::set_names(tolower) +#' dataset_spec <- readxl::read_xlsx(spec_path, sheet = "Datasets") %>% +#' dplyr::rename(label = "Description") %>% +#' rlang::set_names(tolower) +#' +#' adsl %>% +#' xportr_metadata(var_spec, "ADSL", verbose = "warn") %>% +#' xportr_type() %>% +#' xportr_length() %>% +#' xportr_label() %>% +#' xportr_order() %>% +#' xportr_format() %>% +#' xportr_df_label(dataset_spec) %>% +#' xportr_write("adsl.xpt") +#' +#' # `xportr()` can be used to apply a whole pipeline at once +#' xportr(adsl, +#' var_metadata = var_spec, +#' df_metadata = dataset_spec, +#' domain = "ADSL", +#' verbose = "warn", +#' path = "adsl.xpt" +#' ) +#' } +xportr <- function(.df, + var_metadata = NULL, + df_metadata = NULL, + domain = NULL, + verbose = NULL, + path, + strict_checks = FALSE) { + .df %>% + xportr_metadata(var_metadata, domain, verbose) %>% + xportr_type() %>% + xportr_length() %>% + xportr_label() %>% + xportr_order() %>% + xportr_format() %>% + xportr_df_label(dataset_spec) %>% + xportr_write(path) +} diff --git a/man/xportr.Rd b/man/xportr.Rd new file mode 100644 index 00000000..4a391256 --- /dev/null +++ b/man/xportr.Rd @@ -0,0 +1,83 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/xportr.R +\name{xportr} +\alias{xportr} +\title{Wrapper to apply all core xportr functions and write xpt} +\usage{ +xportr( + .df, + var_metadata = NULL, + df_metadata = NULL, + domain = NULL, + verbose = NULL, + path, + strict_checks = FALSE +) +} +\arguments{ +\item{.df}{A data frame of CDISC standard.} + +\item{var_metadata}{A data frame containing variable level metadata} + +\item{df_metadata}{A data frame containing dataset level metadata.} + +\item{domain}{Appropriate CDSIC dataset name, e.g. ADAE, DM. Used to subset +the metadata object. If none is passed, then name of the dataset passed as +.df will be used.} + +\item{verbose}{The action this function takes when an action is taken on the +dataset or function validation finds an issue. See 'Messaging' section for +details. Options are 'stop', 'warn', 'message', and 'none'} + +\item{path}{Path where transport file will be written. File name sans will be +used as \code{xpt} name.} + +\item{strict_checks}{If TRUE, xpt validation will report errors and not write +out the dataset. If FALSE, xpt validation will report warnings and continue +with writing out the dataset. Defaults to FALSE} +} +\value{ +Returns the input dataframe invisibly +} +\description{ +Wrapper to apply all core xportr functions and write xpt +} +\examples{ + +has_pkgs <- require(admiral, quietly = TRUE) && + require(dplyr, quietly = TRUE) && + require(readxl, quietly = TRUE) && + require(rlang, quietly = TRUE) + +if (has_pkgs) { + adsl <- admiral::admiral_adsl + + spec_path <- system.file(paste0("specs/", "ADaM_admiral_spec.xlsx"), package = "xportr") + + var_spec <- readxl::read_xlsx(spec_path, sheet = "Variables") \%>\% + dplyr::rename(type = "Data Type") \%>\% + rlang::set_names(tolower) + dataset_spec <- readxl::read_xlsx(spec_path, sheet = "Datasets") \%>\% + dplyr::rename(label = "Description") \%>\% + rlang::set_names(tolower) + + adsl \%>\% + xportr_metadata(var_spec, "ADSL", verbose = "warn") \%>\% + xportr_type() \%>\% + xportr_length() \%>\% + xportr_label() \%>\% + xportr_order() \%>\% + xportr_format() \%>\% + xportr_df_label(dataset_spec) \%>\% + xportr_write("adsl.xpt") + + # `xportr()` can be used to apply a whole pipeline at once + xportr(adsl, + var_metadata = var_spec, + df_metadata = dataset_spec, + domain = "ADSL", + verbose = "warn", + path = "adsl.xpt" + ) +} +} From 9afeeb5e357ab2df2c0a731d5a86dd94ec01811c Mon Sep 17 00:00:00 2001 From: EeethB Date: Mon, 8 Jan 2024 18:22:56 -0600 Subject: [PATCH 06/26] Correct failing tests --- R/xportr-package.R | 1 + R/xportr.R | 10 +++---- README.Rmd | 4 +-- README.md | 2 +- man/xportr-package.Rd | 2 +- tests/testthat/test-metadata.R | 23 +++++++++------ tests/testthat/test-xportr.R | 52 ++++++++++++++++++++++++++++++++++ 7 files changed, 76 insertions(+), 18 deletions(-) create mode 100644 tests/testthat/test-xportr.R diff --git a/R/xportr-package.R b/R/xportr-package.R index 197ad5be..be1c7bef 100644 --- a/R/xportr-package.R +++ b/R/xportr-package.R @@ -91,6 +91,7 @@ #' #' #' @keywords internal +#' @aliases xportr-package #' #' @import rlang haven #' @importFrom dplyr left_join bind_cols filter select rename rename_with n diff --git a/R/xportr.R b/R/xportr.R index 687e66d6..b0573c68 100644 --- a/R/xportr.R +++ b/R/xportr.R @@ -20,10 +20,10 @@ #' #' @examples #' -#' has_pkgs <- require(admiral, quietly = TRUE) && -#' require(dplyr, quietly = TRUE) && -#' require(readxl, quietly = TRUE) && -#' require(rlang, quietly = TRUE) +#' has_pkgs <- requireNamespace("admiral", quietly = TRUE) && +#' requireNamespace("dplyr", quietly = TRUE) && +#' requireNamespace("readxl", quietly = TRUE) && +#' requireNamespace("rlang", quietly = TRUE) #' #' if (has_pkgs) { #' adsl <- admiral::admiral_adsl @@ -64,7 +64,7 @@ xportr <- function(.df, path, strict_checks = FALSE) { .df %>% - xportr_metadata(var_metadata, domain, verbose) %>% + xportr_metadata(var_metadata, domain = domain, verbose = verbose) %>% xportr_type() %>% xportr_length() %>% xportr_label() %>% diff --git a/README.Rmd b/README.Rmd index edc532c9..c6a9adbd 100644 --- a/README.Rmd +++ b/README.Rmd @@ -143,9 +143,9 @@ adsl %>% The `xportr_metadata()` function can reduce duplication by setting the variable specification and domain explicitly at the top of a pipeline. If you would like to use the `verbose` argument, you will need to set in each function call. -```{r, message=FALSE, eval=FALSE} +```{r, warning=FALSE, message=FALSE, eval=FALSE} adsl %>% - xportr_metadata(var_spec, "ADSL", verbose = "warn") %>% + xportr_metadata(var_spec, domain = "ADSL") %>% xportr_type() %>% xportr_length() %>% xportr_label() %>% diff --git a/README.md b/README.md index cc83fae4..592fcce1 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,7 @@ each function call. ``` r adsl %>% - xportr_metadata(var_spec, "ADSL") %>% + xportr_metadata(var_spec, domain = "ADSL") %>% xportr_type() %>% xportr_length() %>% xportr_label() %>% diff --git a/man/xportr-package.Rd b/man/xportr-package.Rd index 64eaed80..ab8f471e 100644 --- a/man/xportr-package.Rd +++ b/man/xportr-package.Rd @@ -2,8 +2,8 @@ % Please edit documentation in R/xportr-package.R \docType{package} \name{xportr-package} -\alias{xportr} \alias{xportr-package} +\alias{_PACKAGE} \title{The \code{xportr} package} \description{ \code{xportr} is designed to be a clinical workflow friendly method for outputting diff --git a/tests/testthat/test-metadata.R b/tests/testthat/test-metadata.R index 27b80500..97fd0e79 100644 --- a/tests/testthat/test-metadata.R +++ b/tests/testthat/test-metadata.R @@ -594,13 +594,13 @@ test_that("xportr_metadata: Variable ordering messaging is correct", { ) # Metadata versions - xportr_metadata(df, df_meta, verbose = "message") %>% + xportr_metadata(df, df_meta, domain = "df", verbose = "message") %>% xportr_order() %>% expect_message("All variables in specification file are in dataset") %>% expect_condition("4 reordered in dataset") %>% expect_message("Variable reordered in `.df`: `a`, `b`, `c`, and `d`") - xportr_metadata(df2, df_meta, verbose = "message") %>% + xportr_metadata(df2, df_meta, domain = "df2", verbose = "message") %>% xportr_order() %>% expect_message("2 variables not in spec and moved to end") %>% expect_message("Variable moved to end in `.df`: `a` and `z`") %>% @@ -623,13 +623,13 @@ test_that("xportr_type: Variable types are coerced as expected and can raise mes # Metadata version of the last statement df %>% - xportr_metadata(meta_example, verbose = "warn") %>% + xportr_metadata(meta_example, domain = "df", verbose = "warn") %>% xportr_type() %>% expect_warning() # Metadata version df %>% - xportr_metadata(meta_example, verbose = "message") %>% + xportr_metadata(meta_example, domain = "df", verbose = "message") %>% xportr_type() %>% expect_message("Variable type\\(s\\) in dataframe don't match metadata") }) @@ -654,7 +654,8 @@ test_that("xportr_metadata: Check metadata interaction with other functions", { `_xportr.df_metadata_` = var_spec, `_xportr.df_verbose_` = "none"), suppressMessages( - xportr_metadata(adsl, var_spec, domain = "adsl") %>% xportr_type() + xportr_metadata(adsl, var_spec, domain = "adsl", verbose = "none") %>% + xportr_type() ) ) @@ -663,7 +664,8 @@ test_that("xportr_metadata: Check metadata interaction with other functions", { `_xportr.df_metadata_` = var_spec, `_xportr.df_verbose_` = "none"), suppressMessages( - xportr_metadata(adsl, var_spec, domain = "adsl") %>% xportr_length() + xportr_metadata(adsl, var_spec, domain = "adsl", verbose = "none") %>% + xportr_length() ) ) @@ -672,7 +674,8 @@ test_that("xportr_metadata: Check metadata interaction with other functions", { `_xportr.df_metadata_` = var_spec, `_xportr.df_verbose_` = "none"), suppressMessages( - xportr_metadata(adsl, var_spec, domain = "adsl") %>% xportr_label() + xportr_metadata(adsl, var_spec, domain = "adsl", verbose = "none") %>% + xportr_label() ) ) @@ -681,7 +684,8 @@ test_that("xportr_metadata: Check metadata interaction with other functions", { `_xportr.df_metadata_` = var_spec, `_xportr.df_verbose_` = "none"), suppressMessages( - xportr_metadata(adsl, var_spec, domain = "adsl") %>% xportr_order() + xportr_metadata(adsl, var_spec, domain = "adsl", verbose = "none") %>% + xportr_order() ) ) @@ -690,7 +694,8 @@ test_that("xportr_metadata: Check metadata interaction with other functions", { `_xportr.df_metadata_` = var_spec, `_xportr.df_verbose_` = "none"), suppressMessages( - xportr_metadata(adsl, var_spec, domain = "adsl") %>% xportr_format() + xportr_metadata(adsl, var_spec, domain = "adsl", verbose = "none") %>% + xportr_format() ) ) }) diff --git a/tests/testthat/test-xportr.R b/tests/testthat/test-xportr.R new file mode 100644 index 00000000..6ebb129c --- /dev/null +++ b/tests/testthat/test-xportr.R @@ -0,0 +1,52 @@ +test_that("pipeline results match `xportr()` results", { + + has_pkgs <- requireNamespace("admiral", quietly = TRUE) && + requireNamespace("dplyr", quietly = TRUE) && + requireNamespace("readxl", quietly = TRUE) && + requireNamespace("rlang", quietly = TRUE) + + if (has_pkgs) { + adsl <- admiral::admiral_adsl + + spec_path <- system.file(paste0("specs/", "ADaM_admiral_spec.xlsx"), + package = "xportr") + + var_spec <- readxl::read_xlsx(spec_path, sheet = "Variables") %>% + dplyr::rename(type = "Data Type") %>% + rlang::set_names(tolower) + dataset_spec <- readxl::read_xlsx(spec_path, sheet = "Datasets") %>% + dplyr::rename(label = "Description") %>% + rlang::set_names(tolower) + + test_dir <- tempdir() + + pipeline_path <- file.path(test_dir, "adslpipe.xpt") + xportr_path <- file.path(test_dir, "adslxptr.xpt") + + pipeline_df <- adsl %>% + xportr_metadata(var_spec, "ADSL", verbose = "none") %>% + xportr_type() %>% + xportr_length() %>% + xportr_label() %>% + xportr_order() %>% + xportr_format() %>% + xportr_df_label(dataset_spec) %>% + xportr_write(pipeline_path) + + # `xportr()` can be used to apply a whole pipeline at once + xportr_df <- xportr(adsl, + var_metadata = var_spec, + df_metadata = dataset_spec, + domain = "ADSL", + verbose = "none", + path = xportr_path + ) + + expect_identical(pipeline_df, xportr_df) + + expect_identical( + haven::read_xpt(pipeline_path), + haven::read_xpt(xportr_path) + ) + } +}) From f7cf12994cede81e54fefdb8cb1675f6319c4e3e Mon Sep 17 00:00:00 2001 From: EeethB Date: Mon, 8 Jan 2024 18:30:44 -0600 Subject: [PATCH 07/26] Run styler --- man/xportr.Rd | 8 ++++---- tests/testthat/test-metadata.R | 25 +++++++++++++++---------- tests/testthat/test-xportr.R | 4 ++-- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/man/xportr.Rd b/man/xportr.Rd index 4a391256..47da1537 100644 --- a/man/xportr.Rd +++ b/man/xportr.Rd @@ -44,10 +44,10 @@ Wrapper to apply all core xportr functions and write xpt } \examples{ -has_pkgs <- require(admiral, quietly = TRUE) && - require(dplyr, quietly = TRUE) && - require(readxl, quietly = TRUE) && - require(rlang, quietly = TRUE) +has_pkgs <- requireNamespace("admiral", quietly = TRUE) && + requireNamespace("dplyr", quietly = TRUE) && + requireNamespace("readxl", quietly = TRUE) && + requireNamespace("rlang", quietly = TRUE) if (has_pkgs) { adsl <- admiral::admiral_adsl diff --git a/tests/testthat/test-metadata.R b/tests/testthat/test-metadata.R index 97fd0e79..7117b027 100644 --- a/tests/testthat/test-metadata.R +++ b/tests/testthat/test-metadata.R @@ -651,8 +651,9 @@ test_that("xportr_metadata: Check metadata interaction with other functions", { expect_equal( structure(xportr_type(adsl, var_spec, domain = "adsl"), - `_xportr.df_metadata_` = var_spec, - `_xportr.df_verbose_` = "none"), + `_xportr.df_metadata_` = var_spec, + `_xportr.df_verbose_` = "none" + ), suppressMessages( xportr_metadata(adsl, var_spec, domain = "adsl", verbose = "none") %>% xportr_type() @@ -661,8 +662,9 @@ test_that("xportr_metadata: Check metadata interaction with other functions", { expect_equal( structure(xportr_length(adsl, var_spec, domain = "adsl"), - `_xportr.df_metadata_` = var_spec, - `_xportr.df_verbose_` = "none"), + `_xportr.df_metadata_` = var_spec, + `_xportr.df_verbose_` = "none" + ), suppressMessages( xportr_metadata(adsl, var_spec, domain = "adsl", verbose = "none") %>% xportr_length() @@ -671,8 +673,9 @@ test_that("xportr_metadata: Check metadata interaction with other functions", { expect_equal( structure(xportr_label(adsl, var_spec, domain = "adsl"), - `_xportr.df_metadata_` = var_spec, - `_xportr.df_verbose_` = "none"), + `_xportr.df_metadata_` = var_spec, + `_xportr.df_verbose_` = "none" + ), suppressMessages( xportr_metadata(adsl, var_spec, domain = "adsl", verbose = "none") %>% xportr_label() @@ -681,8 +684,9 @@ test_that("xportr_metadata: Check metadata interaction with other functions", { expect_equal( structure(xportr_order(adsl, var_spec, domain = "adsl"), - `_xportr.df_metadata_` = var_spec, - `_xportr.df_verbose_` = "none"), + `_xportr.df_metadata_` = var_spec, + `_xportr.df_verbose_` = "none" + ), suppressMessages( xportr_metadata(adsl, var_spec, domain = "adsl", verbose = "none") %>% xportr_order() @@ -691,8 +695,9 @@ test_that("xportr_metadata: Check metadata interaction with other functions", { expect_equal( structure(xportr_format(adsl, var_spec, domain = "adsl"), - `_xportr.df_metadata_` = var_spec, - `_xportr.df_verbose_` = "none"), + `_xportr.df_metadata_` = var_spec, + `_xportr.df_verbose_` = "none" + ), suppressMessages( xportr_metadata(adsl, var_spec, domain = "adsl", verbose = "none") %>% xportr_format() diff --git a/tests/testthat/test-xportr.R b/tests/testthat/test-xportr.R index 6ebb129c..eb43c244 100644 --- a/tests/testthat/test-xportr.R +++ b/tests/testthat/test-xportr.R @@ -1,5 +1,4 @@ test_that("pipeline results match `xportr()` results", { - has_pkgs <- requireNamespace("admiral", quietly = TRUE) && requireNamespace("dplyr", quietly = TRUE) && requireNamespace("readxl", quietly = TRUE) && @@ -9,7 +8,8 @@ test_that("pipeline results match `xportr()` results", { adsl <- admiral::admiral_adsl spec_path <- system.file(paste0("specs/", "ADaM_admiral_spec.xlsx"), - package = "xportr") + package = "xportr" + ) var_spec <- readxl::read_xlsx(spec_path, sheet = "Variables") %>% dplyr::rename(type = "Data Type") %>% From 0dc0a83fcadd3accab96d0300a9e5599f8373238 Mon Sep 17 00:00:00 2001 From: EeethB Date: Wed, 10 Jan 2024 17:37:00 -0600 Subject: [PATCH 08/26] Correct typo in `xportr()` to pass test --- R/xportr.R | 2 +- tests/testthat/test-xportr.R | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/R/xportr.R b/R/xportr.R index b0573c68..841c2d79 100644 --- a/R/xportr.R +++ b/R/xportr.R @@ -70,6 +70,6 @@ xportr <- function(.df, xportr_label() %>% xportr_order() %>% xportr_format() %>% - xportr_df_label(dataset_spec) %>% + xportr_df_label(df_metadata) %>% xportr_write(path) } diff --git a/tests/testthat/test-xportr.R b/tests/testthat/test-xportr.R index eb43c244..a6c81e8a 100644 --- a/tests/testthat/test-xportr.R +++ b/tests/testthat/test-xportr.R @@ -34,7 +34,8 @@ test_that("pipeline results match `xportr()` results", { xportr_write(pipeline_path) # `xportr()` can be used to apply a whole pipeline at once - xportr_df <- xportr(adsl, + xportr_df <- xportr( + adsl, var_metadata = var_spec, df_metadata = dataset_spec, domain = "ADSL", From 88b0c5e3b8d9cc57dbeb9aec1f50ff3803c8a053 Mon Sep 17 00:00:00 2001 From: EeethB Date: Wed, 10 Jan 2024 17:49:14 -0600 Subject: [PATCH 09/26] Document --- man/metadata.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/metadata.Rd b/man/metadata.Rd index f89f9993..da5de14c 100644 --- a/man/metadata.Rd +++ b/man/metadata.Rd @@ -4,7 +4,7 @@ \alias{xportr_metadata} \title{Set variable specifications and domain} \usage{ -xportr_metadata(.df, metadata, domain = NULL, verbose = NULL) +xportr_metadata(.df, metadata = NULL, domain = NULL, verbose = NULL) } \arguments{ \item{.df}{A data frame of CDISC standard.} From 226f4344231a7bcfc0f8cf2b7704625b358d10dc Mon Sep 17 00:00:00 2001 From: EeethB Date: Thu, 11 Jan 2024 09:56:51 -0600 Subject: [PATCH 10/26] Update xportr() example to use internal data --- NEWS.md | 2 ++ R/xportr.R | 39 +++++++++++++++++------------------- man/xportr.Rd | 39 +++++++++++++++++------------------- tests/testthat/test-xportr.R | 33 ++++++++++-------------------- 4 files changed, 49 insertions(+), 64 deletions(-) diff --git a/NEWS.md b/NEWS.md index 217c5099..1d34c14f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,8 @@ * All `xportr` functions now have `verbose = NULL` as the default. If left `NULL`, the previous default of `getOption("xportr.[fn_name]_verbose")` is used (#151) +* All core functions can be run together by using new function `xportr()` (#137) + ## Documentation ## Deprecation and Breaking Changes diff --git a/R/xportr.R b/R/xportr.R index 841c2d79..3d25f00b 100644 --- a/R/xportr.R +++ b/R/xportr.R @@ -20,40 +20,37 @@ #' #' @examples #' -#' has_pkgs <- requireNamespace("admiral", quietly = TRUE) && -#' requireNamespace("dplyr", quietly = TRUE) && -#' requireNamespace("readxl", quietly = TRUE) && -#' requireNamespace("rlang", quietly = TRUE) +#' if (require(magrittr, quietly = TRUE)) { #' -#' if (has_pkgs) { -#' adsl <- admiral::admiral_adsl +#' test_dir <- tempdir() #' -#' spec_path <- system.file(paste0("specs/", "ADaM_admiral_spec.xlsx"), package = "xportr") +#' pipeline_path <- file.path(test_dir, "adslpipe.xpt") +#' xportr_path <- file.path(test_dir, "adslxptr.xpt") #' -#' var_spec <- readxl::read_xlsx(spec_path, sheet = "Variables") %>% -#' dplyr::rename(type = "Data Type") %>% -#' rlang::set_names(tolower) -#' dataset_spec <- readxl::read_xlsx(spec_path, sheet = "Datasets") %>% -#' dplyr::rename(label = "Description") %>% -#' rlang::set_names(tolower) +#' dataset_spec_low <- setNames(dataset_spec, tolower(names(dataset_spec))) +#' names(dataset_spec_low)[[2]] <- "label" +#' +#' var_spec_low <- setNames(var_spec, tolower(names(var_spec))) +#' names(var_spec_low)[[5]] <- "type" #' #' adsl %>% -#' xportr_metadata(var_spec, "ADSL", verbose = "warn") %>% +#' xportr_metadata(var_spec_low, "ADSL", verbose = "none") %>% #' xportr_type() %>% #' xportr_length() %>% #' xportr_label() %>% #' xportr_order() %>% #' xportr_format() %>% -#' xportr_df_label(dataset_spec) %>% -#' xportr_write("adsl.xpt") +#' xportr_df_label(dataset_spec_low) %>% +#' xportr_write(pipeline_path) #' #' # `xportr()` can be used to apply a whole pipeline at once -#' xportr(adsl, -#' var_metadata = var_spec, -#' df_metadata = dataset_spec, +#' xportr( +#' adsl, +#' var_metadata = var_spec_low, +#' df_metadata = dataset_spec_low, #' domain = "ADSL", -#' verbose = "warn", -#' path = "adsl.xpt" +#' verbose = "none", +#' path = xportr_path #' ) #' } xportr <- function(.df, diff --git a/man/xportr.Rd b/man/xportr.Rd index 47da1537..fcded870 100644 --- a/man/xportr.Rd +++ b/man/xportr.Rd @@ -44,40 +44,37 @@ Wrapper to apply all core xportr functions and write xpt } \examples{ -has_pkgs <- requireNamespace("admiral", quietly = TRUE) && - requireNamespace("dplyr", quietly = TRUE) && - requireNamespace("readxl", quietly = TRUE) && - requireNamespace("rlang", quietly = TRUE) +if (require(magrittr, quietly = TRUE)) { -if (has_pkgs) { - adsl <- admiral::admiral_adsl + test_dir <- tempdir() - spec_path <- system.file(paste0("specs/", "ADaM_admiral_spec.xlsx"), package = "xportr") + pipeline_path <- file.path(test_dir, "adslpipe.xpt") + xportr_path <- file.path(test_dir, "adslxptr.xpt") - var_spec <- readxl::read_xlsx(spec_path, sheet = "Variables") \%>\% - dplyr::rename(type = "Data Type") \%>\% - rlang::set_names(tolower) - dataset_spec <- readxl::read_xlsx(spec_path, sheet = "Datasets") \%>\% - dplyr::rename(label = "Description") \%>\% - rlang::set_names(tolower) + dataset_spec_low <- setNames(dataset_spec, tolower(names(dataset_spec))) + names(dataset_spec_low)[[2]] <- "label" + + var_spec_low <- setNames(var_spec, tolower(names(var_spec))) + names(var_spec_low)[[5]] <- "type" adsl \%>\% - xportr_metadata(var_spec, "ADSL", verbose = "warn") \%>\% + xportr_metadata(var_spec_low, "ADSL", verbose = "none") \%>\% xportr_type() \%>\% xportr_length() \%>\% xportr_label() \%>\% xportr_order() \%>\% xportr_format() \%>\% - xportr_df_label(dataset_spec) \%>\% - xportr_write("adsl.xpt") + xportr_df_label(dataset_spec_low) \%>\% + xportr_write(pipeline_path) # `xportr()` can be used to apply a whole pipeline at once - xportr(adsl, - var_metadata = var_spec, - df_metadata = dataset_spec, + xportr( + adsl, + var_metadata = var_spec_low, + df_metadata = dataset_spec_low, domain = "ADSL", - verbose = "warn", - path = "adsl.xpt" + verbose = "none", + path = xportr_path ) } } diff --git a/tests/testthat/test-xportr.R b/tests/testthat/test-xportr.R index a6c81e8a..908dc03e 100644 --- a/tests/testthat/test-xportr.R +++ b/tests/testthat/test-xportr.R @@ -1,43 +1,32 @@ test_that("pipeline results match `xportr()` results", { - has_pkgs <- requireNamespace("admiral", quietly = TRUE) && - requireNamespace("dplyr", quietly = TRUE) && - requireNamespace("readxl", quietly = TRUE) && - requireNamespace("rlang", quietly = TRUE) - - if (has_pkgs) { - adsl <- admiral::admiral_adsl - - spec_path <- system.file(paste0("specs/", "ADaM_admiral_spec.xlsx"), - package = "xportr" - ) - - var_spec <- readxl::read_xlsx(spec_path, sheet = "Variables") %>% - dplyr::rename(type = "Data Type") %>% - rlang::set_names(tolower) - dataset_spec <- readxl::read_xlsx(spec_path, sheet = "Datasets") %>% - dplyr::rename(label = "Description") %>% - rlang::set_names(tolower) + if (require(magrittr, quietly = TRUE)) { test_dir <- tempdir() pipeline_path <- file.path(test_dir, "adslpipe.xpt") xportr_path <- file.path(test_dir, "adslxptr.xpt") + dataset_spec_low <- setNames(dataset_spec, tolower(names(dataset_spec))) + names(dataset_spec_low)[[2]] <- "label" + + var_spec_low <- setNames(var_spec, tolower(names(var_spec))) + names(var_spec_low)[[5]] <- "type" + pipeline_df <- adsl %>% - xportr_metadata(var_spec, "ADSL", verbose = "none") %>% + xportr_metadata(var_spec_low, "ADSL", verbose = "none") %>% xportr_type() %>% xportr_length() %>% xportr_label() %>% xportr_order() %>% xportr_format() %>% - xportr_df_label(dataset_spec) %>% + xportr_df_label(dataset_spec_low) %>% xportr_write(pipeline_path) # `xportr()` can be used to apply a whole pipeline at once xportr_df <- xportr( adsl, - var_metadata = var_spec, - df_metadata = dataset_spec, + var_metadata = var_spec_low, + df_metadata = dataset_spec_low, domain = "ADSL", verbose = "none", path = xportr_path From 517c84a2c5aef0df470ff85939c47cbebd74ebea Mon Sep 17 00:00:00 2001 From: EeethB Date: Thu, 11 Jan 2024 09:57:08 -0600 Subject: [PATCH 11/26] Style --- R/xportr.R | 1 - tests/testthat/test-xportr.R | 1 - 2 files changed, 2 deletions(-) diff --git a/R/xportr.R b/R/xportr.R index 3d25f00b..8ac85a71 100644 --- a/R/xportr.R +++ b/R/xportr.R @@ -21,7 +21,6 @@ #' @examples #' #' if (require(magrittr, quietly = TRUE)) { -#' #' test_dir <- tempdir() #' #' pipeline_path <- file.path(test_dir, "adslpipe.xpt") diff --git a/tests/testthat/test-xportr.R b/tests/testthat/test-xportr.R index 908dc03e..6711a668 100644 --- a/tests/testthat/test-xportr.R +++ b/tests/testthat/test-xportr.R @@ -1,6 +1,5 @@ test_that("pipeline results match `xportr()` results", { if (require(magrittr, quietly = TRUE)) { - test_dir <- tempdir() pipeline_path <- file.path(test_dir, "adslpipe.xpt") From e8831219b989c1eaeb27b6542491916f0f4c5084 Mon Sep 17 00:00:00 2001 From: EeethB Date: Thu, 11 Jan 2024 10:28:15 -0600 Subject: [PATCH 12/26] Add `xportr()` to pkgdown reference --- _pkgdown.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/_pkgdown.yml b/_pkgdown.yml index dbeae1cc..2c2184eb 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -32,6 +32,7 @@ reference: - xportr_order - xportr_df_label - xportr_metadata + - xportr - title: xportr helper functions desc: Utility functions called within core xportr functions From 63beadffea8218818a1af3370a77912d9f33c893 Mon Sep 17 00:00:00 2001 From: EeethB Date: Fri, 19 Jan 2024 18:03:09 -0600 Subject: [PATCH 13/26] Streamline documentation --- R/format.R | 6 +++--- R/length.R | 10 +--------- man/metadata.Rd | 4 ++-- man/xportr_df_label.Rd | 7 ++----- man/xportr_format.Rd | 13 +++++-------- man/xportr_label.Rd | 7 ++----- man/xportr_length.Rd | 7 ++----- man/xportr_order.Rd | 7 ++----- man/xportr_type.Rd | 7 ++----- man/xportr_write.Rd | 4 ++-- 10 files changed, 23 insertions(+), 49 deletions(-) diff --git a/R/format.R b/R/format.R index 4e4c37c8..2b5a1190 100644 --- a/R/format.R +++ b/R/format.R @@ -18,9 +18,9 @@ #' "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. +#' 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: #' "variable". This is used to match columns in '.df' argument and the diff --git a/R/length.R b/R/length.R index f8fe3b66..44f7df3a 100644 --- a/R/length.R +++ b/R/length.R @@ -5,17 +5,9 @@ #' character columns, and 8 for non-character columns. This value is stored in #' the 'width' attribute of the column. #' -#' @param .df A data frame of CDISC standard. +#' @inheritParams xportr #' @param metadata A data frame containing variable level metadata. See #' 'Metadata' section for details. -#' @param domain Appropriate CDSIC dataset name, e.g. ADAE, DM. Used to subset -#' the metadata object. If none is passed, then [xportr_metadata()] must be -#' called before hand to set the domain as an attribute of `.df`. -#' @param verbose The action this function takes when an action is taken on the -#' dataset or function validation finds an issue. See 'Messaging' section for -#' details. Options are 'stop', 'warn', 'message', and 'none' -#' @param metacore `r lifecycle::badge("deprecated")` Previously used to pass -#' metadata now renamed with `metadata` #' #' @section Messaging: `length_log` is the primary messaging tool for #' `xportr_length`. If there are any columns present in the '.df' that are not diff --git a/man/metadata.Rd b/man/metadata.Rd index da5de14c..30918a0c 100644 --- a/man/metadata.Rd +++ b/man/metadata.Rd @@ -13,8 +13,8 @@ xportr_metadata(.df, metadata = NULL, domain = NULL, verbose = NULL) 'Metadata' section for details.} \item{domain}{Appropriate CDSIC dataset name, e.g. ADAE, DM. Used to subset -the metadata object. If none is passed, then \code{\link[=xportr_metadata]{xportr_metadata()}} must be -called before hand to set the domain as an attribute of \code{.df}.} +the metadata object. If none is passed, then name of the dataset passed as +.df will be used.} \item{verbose}{The action this function takes when an action is taken on the dataset or function validation finds an issue. See 'Messaging' section for diff --git a/man/xportr_df_label.Rd b/man/xportr_df_label.Rd index 363c59c4..00f296bd 100644 --- a/man/xportr_df_label.Rd +++ b/man/xportr_df_label.Rd @@ -13,11 +13,8 @@ xportr_df_label(.df, metadata = NULL, domain = NULL, metacore = deprecated()) details.} \item{domain}{Appropriate CDSIC dataset name, e.g. ADAE, DM. Used to subset -the metadata object. If none is passed, then \code{\link[=xportr_metadata]{xportr_metadata()}} must be -called before hand to set the domain as an attribute of \code{.df}.} - -\item{metacore}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Previously used to pass -metadata now renamed with \code{metadata}} +the metadata object. If none is passed, then name of the dataset passed as +.df will be used.} } \value{ Data frame with label attributes. diff --git a/man/xportr_format.Rd b/man/xportr_format.Rd index dd883554..1ea51e60 100644 --- a/man/xportr_format.Rd +++ b/man/xportr_format.Rd @@ -13,11 +13,8 @@ xportr_format(.df, metadata = NULL, domain = NULL, metacore = deprecated()) 'Metadata' section for details.} \item{domain}{Appropriate CDSIC dataset name, e.g. ADAE, DM. Used to subset -the metadata object. If none is passed, then \code{\link[=xportr_metadata]{xportr_metadata()}} must be -called before hand to set the domain as an attribute of \code{.df}.} - -\item{metacore}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Previously used to pass -metadata now renamed with \code{metadata}} +the metadata object. If none is passed, then name of the dataset passed as +.df will be used.} } \value{ Data frame with \code{SASformat} attributes for each variable. @@ -37,9 +34,9 @@ For data.frame 'metadata' arguments three 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 '\code{format.sas}' attribute of -the column. This is passed to \code{haven::write} to note the format. +\item Format Name - passed as the 'xportr.format_name' option. Default: +"format". Character values to update the '\code{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. diff --git a/man/xportr_label.Rd b/man/xportr_label.Rd index f408de4f..26346818 100644 --- a/man/xportr_label.Rd +++ b/man/xportr_label.Rd @@ -19,15 +19,12 @@ xportr_label( 'Metadata' section for details.} \item{domain}{Appropriate CDSIC dataset name, e.g. ADAE, DM. Used to subset -the metadata object. If none is passed, then \code{\link[=xportr_metadata]{xportr_metadata()}} must be -called before hand to set the domain as an attribute of \code{.df}.} +the metadata object. If none is passed, then name of the dataset passed as +.df will be used.} \item{verbose}{The action this function takes when an action is taken on the dataset or function validation finds an issue. See 'Messaging' section for details. Options are 'stop', 'warn', 'message', and 'none'} - -\item{metacore}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Previously used to pass -metadata now renamed with \code{metadata}} } \value{ Data frame with label attributes for each variable. diff --git a/man/xportr_length.Rd b/man/xportr_length.Rd index fd8c6807..853f0b48 100644 --- a/man/xportr_length.Rd +++ b/man/xportr_length.Rd @@ -19,15 +19,12 @@ xportr_length( 'Metadata' section for details.} \item{domain}{Appropriate CDSIC dataset name, e.g. ADAE, DM. Used to subset -the metadata object. If none is passed, then \code{\link[=xportr_metadata]{xportr_metadata()}} must be -called before hand to set the domain as an attribute of \code{.df}.} +the metadata object. If none is passed, then name of the dataset passed as +.df will be used.} \item{verbose}{The action this function takes when an action is taken on the dataset or function validation finds an issue. See 'Messaging' section for details. Options are 'stop', 'warn', 'message', and 'none'} - -\item{metacore}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Previously used to pass -metadata now renamed with \code{metadata}} } \value{ Data frame with \code{SASlength} attributes for each variable. diff --git a/man/xportr_order.Rd b/man/xportr_order.Rd index 9cefd0fb..b50d148e 100644 --- a/man/xportr_order.Rd +++ b/man/xportr_order.Rd @@ -19,15 +19,12 @@ xportr_order( 'Metadata' section for details.} \item{domain}{Appropriate CDSIC dataset name, e.g. ADAE, DM. Used to subset -the metadata object. If none is passed, then \code{\link[=xportr_metadata]{xportr_metadata()}} must be -called before hand to set the domain as an attribute of \code{.df}.} +the metadata object. If none is passed, then name of the dataset passed as +.df will be used.} \item{verbose}{The action this function takes when an action is taken on the dataset or function validation finds an issue. See 'Messaging' section for details. Options are 'stop', 'warn', 'message', and 'none'} - -\item{metacore}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Previously used to pass -metadata now renamed with \code{metadata}} } \value{ Dataframe that has been re-ordered according to spec diff --git a/man/xportr_type.Rd b/man/xportr_type.Rd index cbbbbef9..051f63bb 100644 --- a/man/xportr_type.Rd +++ b/man/xportr_type.Rd @@ -19,15 +19,12 @@ xportr_type( 'Metadata' section for details.} \item{domain}{Appropriate CDSIC dataset name, e.g. ADAE, DM. Used to subset -the metadata object. If none is passed, then \code{\link[=xportr_metadata]{xportr_metadata()}} must be -called before hand to set the domain as an attribute of \code{.df}.} +the metadata object. If none is passed, then name of the dataset passed as +.df will be used.} \item{verbose}{The action this function takes when an action is taken on the dataset or function validation finds an issue. See 'Messaging' section for details. Options are 'stop', 'warn', 'message', and 'none'} - -\item{metacore}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Previously used to pass -metadata now renamed with \code{metadata}} } \value{ Returns the modified table. diff --git a/man/xportr_write.Rd b/man/xportr_write.Rd index b85f1766..db739e9c 100644 --- a/man/xportr_write.Rd +++ b/man/xportr_write.Rd @@ -23,8 +23,8 @@ used as \code{xpt} name.} 'Metadata' section for details.} \item{domain}{Appropriate CDSIC dataset name, e.g. ADAE, DM. Used to subset -the metadata object. If none is passed, then \code{\link[=xportr_metadata]{xportr_metadata()}} must be -called before hand to set the domain as an attribute of \code{.df}.} +the metadata object. If none is passed, then name of the dataset passed as +.df will be used.} \item{strict_checks}{If TRUE, xpt validation will report errors and not write out the dataset. If FALSE, xpt validation will report warnings and continue From a729e5cbb497bc7adb1ceb6c998d2ef335fa45be Mon Sep 17 00:00:00 2001 From: EeethB Date: Fri, 19 Jan 2024 18:05:03 -0600 Subject: [PATCH 14/26] Streamline documentation --- R/length.R | 2 ++ man/xportr_df_label.Rd | 3 +++ man/xportr_format.Rd | 3 +++ man/xportr_label.Rd | 3 +++ man/xportr_length.Rd | 3 +++ man/xportr_order.Rd | 3 +++ man/xportr_type.Rd | 3 +++ 7 files changed, 20 insertions(+) diff --git a/R/length.R b/R/length.R index 44f7df3a..05fadffd 100644 --- a/R/length.R +++ b/R/length.R @@ -8,6 +8,8 @@ #' @inheritParams xportr #' @param metadata A data frame containing variable level metadata. See #' 'Metadata' section for details. +#' @param metacore `r lifecycle::badge("deprecated")` Previously used to pass +#' metadata now renamed with `metadata` #' #' @section Messaging: `length_log` is the primary messaging tool for #' `xportr_length`. If there are any columns present in the '.df' that are not diff --git a/man/xportr_df_label.Rd b/man/xportr_df_label.Rd index 00f296bd..691de990 100644 --- a/man/xportr_df_label.Rd +++ b/man/xportr_df_label.Rd @@ -15,6 +15,9 @@ details.} \item{domain}{Appropriate CDSIC dataset name, e.g. ADAE, DM. Used to subset the metadata object. If none is passed, then name of the dataset passed as .df will be used.} + +\item{metacore}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Previously used to pass +metadata now renamed with \code{metadata}} } \value{ Data frame with label attributes. diff --git a/man/xportr_format.Rd b/man/xportr_format.Rd index 1ea51e60..e085a345 100644 --- a/man/xportr_format.Rd +++ b/man/xportr_format.Rd @@ -15,6 +15,9 @@ xportr_format(.df, metadata = NULL, domain = NULL, metacore = deprecated()) \item{domain}{Appropriate CDSIC dataset name, e.g. ADAE, DM. Used to subset the metadata object. If none is passed, then name of the dataset passed as .df will be used.} + +\item{metacore}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Previously used to pass +metadata now renamed with \code{metadata}} } \value{ Data frame with \code{SASformat} attributes for each variable. diff --git a/man/xportr_label.Rd b/man/xportr_label.Rd index 26346818..eb03df81 100644 --- a/man/xportr_label.Rd +++ b/man/xportr_label.Rd @@ -25,6 +25,9 @@ the metadata object. If none is passed, then name of the dataset passed as \item{verbose}{The action this function takes when an action is taken on the dataset or function validation finds an issue. See 'Messaging' section for details. Options are 'stop', 'warn', 'message', and 'none'} + +\item{metacore}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Previously used to pass +metadata now renamed with \code{metadata}} } \value{ Data frame with label attributes for each variable. diff --git a/man/xportr_length.Rd b/man/xportr_length.Rd index 853f0b48..f7a7c689 100644 --- a/man/xportr_length.Rd +++ b/man/xportr_length.Rd @@ -25,6 +25,9 @@ the metadata object. If none is passed, then name of the dataset passed as \item{verbose}{The action this function takes when an action is taken on the dataset or function validation finds an issue. See 'Messaging' section for details. Options are 'stop', 'warn', 'message', and 'none'} + +\item{metacore}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Previously used to pass +metadata now renamed with \code{metadata}} } \value{ Data frame with \code{SASlength} attributes for each variable. diff --git a/man/xportr_order.Rd b/man/xportr_order.Rd index b50d148e..26b87f42 100644 --- a/man/xportr_order.Rd +++ b/man/xportr_order.Rd @@ -25,6 +25,9 @@ the metadata object. If none is passed, then name of the dataset passed as \item{verbose}{The action this function takes when an action is taken on the dataset or function validation finds an issue. See 'Messaging' section for details. Options are 'stop', 'warn', 'message', and 'none'} + +\item{metacore}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Previously used to pass +metadata now renamed with \code{metadata}} } \value{ Dataframe that has been re-ordered according to spec diff --git a/man/xportr_type.Rd b/man/xportr_type.Rd index 051f63bb..21eb3583 100644 --- a/man/xportr_type.Rd +++ b/man/xportr_type.Rd @@ -25,6 +25,9 @@ the metadata object. If none is passed, then name of the dataset passed as \item{verbose}{The action this function takes when an action is taken on the dataset or function validation finds an issue. See 'Messaging' section for details. Options are 'stop', 'warn', 'message', and 'none'} + +\item{metacore}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Previously used to pass +metadata now renamed with \code{metadata}} } \value{ Returns the modified table. From c122df659356ff973feee46ae48a9b0c8c12fcde Mon Sep 17 00:00:00 2001 From: Ethan Brockmann <59264453+EeethB@users.noreply.github.com> Date: Mon, 22 Jan 2024 09:12:15 -0600 Subject: [PATCH 15/26] Adjust magrittr-conditional example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com> --- R/xportr.R | 56 ++++++++++++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/R/xportr.R b/R/xportr.R index 8ac85a71..ed7c3ba1 100644 --- a/R/xportr.R +++ b/R/xportr.R @@ -18,40 +18,38 @@ #' @return Returns the input dataframe invisibly #' @export #' -#' @examples +#' @examplesIf requireNamespace("magrittr") +#' library(magrittr) +#' test_dir <- tempdir() #' -#' if (require(magrittr, quietly = TRUE)) { -#' test_dir <- tempdir() +#' pipeline_path <- file.path(test_dir, "adslpipe.xpt") +#' xportr_path <- file.path(test_dir, "adslxptr.xpt") #' -#' pipeline_path <- file.path(test_dir, "adslpipe.xpt") -#' xportr_path <- file.path(test_dir, "adslxptr.xpt") +#' dataset_spec_low <- setNames(dataset_spec, tolower(names(dataset_spec))) +#' names(dataset_spec_low)[[2]] <- "label" #' -#' dataset_spec_low <- setNames(dataset_spec, tolower(names(dataset_spec))) -#' names(dataset_spec_low)[[2]] <- "label" +#' var_spec_low <- setNames(var_spec, tolower(names(var_spec))) +#' names(var_spec_low)[[5]] <- "type" #' -#' var_spec_low <- setNames(var_spec, tolower(names(var_spec))) -#' names(var_spec_low)[[5]] <- "type" +#' adsl %>% +#' xportr_metadata(var_spec_low, "ADSL", verbose = "none") %>% +#' xportr_type() %>% +#' xportr_length() %>% +#' xportr_label() %>% +#' xportr_order() %>% +#' xportr_format() %>% +#' xportr_df_label(dataset_spec_low) %>% +#' xportr_write(pipeline_path) #' -#' adsl %>% -#' xportr_metadata(var_spec_low, "ADSL", verbose = "none") %>% -#' xportr_type() %>% -#' xportr_length() %>% -#' xportr_label() %>% -#' xportr_order() %>% -#' xportr_format() %>% -#' xportr_df_label(dataset_spec_low) %>% -#' xportr_write(pipeline_path) -#' -#' # `xportr()` can be used to apply a whole pipeline at once -#' xportr( -#' adsl, -#' var_metadata = var_spec_low, -#' df_metadata = dataset_spec_low, -#' domain = "ADSL", -#' verbose = "none", -#' path = xportr_path -#' ) -#' } +#' # `xportr()` can be used to apply a whole pipeline at once +#' xportr( +#' adsl, +#' var_metadata = var_spec_low, +#' df_metadata = dataset_spec_low, +#' domain = "ADSL", +#' verbose = "none", +#' path = xportr_path +#' ) xportr <- function(.df, var_metadata = NULL, df_metadata = NULL, From b4a50ca4d9f7465367490b92b6ed66ea876ac03c Mon Sep 17 00:00:00 2001 From: Ethan Brockmann <59264453+EeethB@users.noreply.github.com> Date: Mon, 22 Jan 2024 11:29:28 -0600 Subject: [PATCH 16/26] Update metadata tests to remove unnecessary messaging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com> --- tests/testthat/test-metadata.R | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/testthat/test-metadata.R b/tests/testthat/test-metadata.R index bd0c1ba4..3c841e72 100644 --- a/tests/testthat/test-metadata.R +++ b/tests/testthat/test-metadata.R @@ -649,6 +649,12 @@ test_that("xportr_metadata: Check metadata interaction with other functions", { dplyr::rename(type = "Data Type") %>% rlang::set_names(tolower) + # Divert all messages to tempfile, instead of printing them + # note: be aware as this should only be used in tests that don't track + # messages + if (requireNamespace("withr", quiet = TRUE) { + withr::local_message_sink(withr::local_tempfile()) + } expect_equal( structure(xportr_type(adsl, var_spec, domain = "adsl"), `_xportr.df_metadata_` = var_spec, From 5a7f78bce3f4859bd62c4d53a397653192c3e3e4 Mon Sep 17 00:00:00 2001 From: Ethan Brockmann <59264453+EeethB@users.noreply.github.com> Date: Mon, 22 Jan 2024 11:30:10 -0600 Subject: [PATCH 17/26] Update `xportr()` tests to remove unnecessary messaging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com> --- tests/testthat/test-xportr.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/testthat/test-xportr.R b/tests/testthat/test-xportr.R index 6711a668..0b1aa8ee 100644 --- a/tests/testthat/test-xportr.R +++ b/tests/testthat/test-xportr.R @@ -11,6 +11,10 @@ test_that("pipeline results match `xportr()` results", { var_spec_low <- setNames(var_spec, tolower(names(var_spec))) names(var_spec_low)[[5]] <- "type" + # Divert all messages to tempfile, instead of printing them + # note: be aware as this should only be used in tests that don't track + # messages + withr::local_message_sink(withr::local_tempfile()) pipeline_df <- adsl %>% xportr_metadata(var_spec_low, "ADSL", verbose = "none") %>% xportr_type() %>% From 5e723be50ea184e55f1ed353e838e216977a6839 Mon Sep 17 00:00:00 2001 From: Ethan Brockmann <59264453+EeethB@users.noreply.github.com> Date: Mon, 22 Jan 2024 11:31:09 -0600 Subject: [PATCH 18/26] Update `xportr()` tests to remove unnecessary messaging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com> --- tests/testthat/test-xportr.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/testthat/test-xportr.R b/tests/testthat/test-xportr.R index 0b1aa8ee..6c216c94 100644 --- a/tests/testthat/test-xportr.R +++ b/tests/testthat/test-xportr.R @@ -11,6 +11,10 @@ test_that("pipeline results match `xportr()` results", { var_spec_low <- setNames(var_spec, tolower(names(var_spec))) names(var_spec_low)[[5]] <- "type" + # Divert all messages to tempfile, instead of printing them + # note: be aware as this should only be used in tests that don't track + # messages + withr::local_message_sink(withr::local_tempfile()) # Divert all messages to tempfile, instead of printing them # note: be aware as this should only be used in tests that don't track # messages From d0bc225f92e6065317132d8ba190e7db824f5d89 Mon Sep 17 00:00:00 2001 From: Ethan Brockmann <59264453+EeethB@users.noreply.github.com> Date: Mon, 22 Jan 2024 11:32:09 -0600 Subject: [PATCH 19/26] Update temp files to use `local_file()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com> --- tests/testthat/test-xportr.R | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-xportr.R b/tests/testthat/test-xportr.R index 6c216c94..70c2b8a5 100644 --- a/tests/testthat/test-xportr.R +++ b/tests/testthat/test-xportr.R @@ -1,9 +1,8 @@ test_that("pipeline results match `xportr()` results", { if (require(magrittr, quietly = TRUE)) { - test_dir <- tempdir() - - pipeline_path <- file.path(test_dir, "adslpipe.xpt") - xportr_path <- file.path(test_dir, "adslxptr.xpt") + skip_if_not_installed("withr") + trad_path <- withr::local_file("adslpipe.xpt") + metadata_path <- withr::local_file("adslxptr.xpt") dataset_spec_low <- setNames(dataset_spec, tolower(names(dataset_spec))) names(dataset_spec_low)[[2]] <- "label" From 4eea1660108143e861bd02625a36f5a2197312a3 Mon Sep 17 00:00:00 2001 From: Ethan Brockmann <59264453+EeethB@users.noreply.github.com> Date: Mon, 22 Jan 2024 11:32:34 -0600 Subject: [PATCH 20/26] Update temp files to use `local_file()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com> --- tests/testthat/test-metadata.R | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-metadata.R b/tests/testthat/test-metadata.R index 3c841e72..75ef09d4 100644 --- a/tests/testthat/test-metadata.R +++ b/tests/testthat/test-metadata.R @@ -758,10 +758,9 @@ test_that("xportr_*: Domain is kept in between calls", { test_that("`xportr_metadata()` results match traditional results", { if (require(magrittr, quietly = TRUE)) { - test_dir <- tempdir() - - trad_path <- file.path(test_dir, "adsltrad.xpt") - metadata_path <- file.path(test_dir, "adslmeta.xpt") + skip_if_not_installed("withr") + trad_path <- withr::local_file("adsltrad.xpt") + metadata_path <- withr::local_file("adslmeta.xpt") dataset_spec_low <- setNames(dataset_spec, tolower(names(dataset_spec))) names(dataset_spec_low)[[2]] <- "label" From e2f7e252e2fc5e7badd3319912a08203d3018f7f Mon Sep 17 00:00:00 2001 From: EeethB Date: Mon, 22 Jan 2024 12:41:59 -0500 Subject: [PATCH 21/26] Fix unmatched paren in tests --- man/xportr.Rd | 56 +++++++++++++++++----------------- tests/testthat/test-metadata.R | 2 +- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/man/xportr.Rd b/man/xportr.Rd index 0d2c3174..c810dae1 100644 --- a/man/xportr.Rd +++ b/man/xportr.Rd @@ -43,37 +43,37 @@ Returns the input dataframe invisibly Wrapper to apply all core xportr functions and write xpt } \examples{ +\dontshow{if (requireNamespace("magrittr")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +library(magrittr) +test_dir <- tempdir() -if (require(magrittr, quietly = TRUE)) { - test_dir <- tempdir() +pipeline_path <- file.path(test_dir, "adslpipe.xpt") +xportr_path <- file.path(test_dir, "adslxptr.xpt") - pipeline_path <- file.path(test_dir, "adslpipe.xpt") - xportr_path <- file.path(test_dir, "adslxptr.xpt") +dataset_spec_low <- setNames(dataset_spec, tolower(names(dataset_spec))) +names(dataset_spec_low)[[2]] <- "label" - dataset_spec_low <- setNames(dataset_spec, tolower(names(dataset_spec))) - names(dataset_spec_low)[[2]] <- "label" +var_spec_low <- setNames(var_spec, tolower(names(var_spec))) +names(var_spec_low)[[5]] <- "type" - var_spec_low <- setNames(var_spec, tolower(names(var_spec))) - names(var_spec_low)[[5]] <- "type" +adsl \%>\% + xportr_metadata(var_spec_low, "ADSL", verbose = "none") \%>\% + xportr_type() \%>\% + xportr_length() \%>\% + xportr_label() \%>\% + xportr_order() \%>\% + xportr_format() \%>\% + xportr_df_label(dataset_spec_low) \%>\% + xportr_write(pipeline_path) - adsl \%>\% - xportr_metadata(var_spec_low, "ADSL", verbose = "none") \%>\% - xportr_type() \%>\% - xportr_length() \%>\% - xportr_label() \%>\% - xportr_order() \%>\% - xportr_format() \%>\% - xportr_df_label(dataset_spec_low) \%>\% - xportr_write(pipeline_path) - - # `xportr()` can be used to apply a whole pipeline at once - xportr( - adsl, - var_metadata = var_spec_low, - df_metadata = dataset_spec_low, - domain = "ADSL", - verbose = "none", - path = xportr_path - ) -} +# `xportr()` can be used to apply a whole pipeline at once +xportr( + adsl, + var_metadata = var_spec_low, + df_metadata = dataset_spec_low, + domain = "ADSL", + verbose = "none", + path = xportr_path +) +\dontshow{\}) # examplesIf} } diff --git a/tests/testthat/test-metadata.R b/tests/testthat/test-metadata.R index 75ef09d4..61fe9112 100644 --- a/tests/testthat/test-metadata.R +++ b/tests/testthat/test-metadata.R @@ -652,7 +652,7 @@ test_that("xportr_metadata: Check metadata interaction with other functions", { # Divert all messages to tempfile, instead of printing them # note: be aware as this should only be used in tests that don't track # messages - if (requireNamespace("withr", quiet = TRUE) { + if (requireNamespace("withr", quiet = TRUE)) { withr::local_message_sink(withr::local_tempfile()) } expect_equal( From 1e992a920812a7cd604fb70912de9ed7c3883c61 Mon Sep 17 00:00:00 2001 From: EeethB Date: Mon, 22 Jan 2024 12:46:09 -0500 Subject: [PATCH 22/26] Remove duplicate comment --- tests/testthat/test-xportr.R | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/testthat/test-xportr.R b/tests/testthat/test-xportr.R index 70c2b8a5..097ad277 100644 --- a/tests/testthat/test-xportr.R +++ b/tests/testthat/test-xportr.R @@ -10,14 +10,10 @@ test_that("pipeline results match `xportr()` results", { var_spec_low <- setNames(var_spec, tolower(names(var_spec))) names(var_spec_low)[[5]] <- "type" - # Divert all messages to tempfile, instead of printing them - # note: be aware as this should only be used in tests that don't track - # messages - withr::local_message_sink(withr::local_tempfile()) - # Divert all messages to tempfile, instead of printing them - # note: be aware as this should only be used in tests that don't track - # messages - withr::local_message_sink(withr::local_tempfile()) + # Divert all messages to tempfile, instead of printing them + # note: be aware as this should only be used in tests that don't track + # messages + withr::local_message_sink(withr::local_tempfile()) pipeline_df <- adsl %>% xportr_metadata(var_spec_low, "ADSL", verbose = "none") %>% xportr_type() %>% From 065097fc7c29e8cbd56aea06136af571957a7907 Mon Sep 17 00:00:00 2001 From: EeethB Date: Mon, 22 Jan 2024 12:59:31 -0500 Subject: [PATCH 23/26] Fix error in test file path --- tests/testthat/test-xportr.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-xportr.R b/tests/testthat/test-xportr.R index 097ad277..60161a72 100644 --- a/tests/testthat/test-xportr.R +++ b/tests/testthat/test-xportr.R @@ -1,8 +1,8 @@ test_that("pipeline results match `xportr()` results", { if (require(magrittr, quietly = TRUE)) { skip_if_not_installed("withr") - trad_path <- withr::local_file("adslpipe.xpt") - metadata_path <- withr::local_file("adslxptr.xpt") + pipeline_path <- withr::local_file("adslpipe.xpt") + xportr_path <- withr::local_file("adslxptr.xpt") dataset_spec_low <- setNames(dataset_spec, tolower(names(dataset_spec))) names(dataset_spec_low)[[2]] <- "label" From 5d971f221c043d2933651959c3074eed990dff59 Mon Sep 17 00:00:00 2001 From: EeethB Date: Mon, 29 Jan 2024 11:43:27 -0500 Subject: [PATCH 24/26] Add `xportr()` to README --- README.Rmd | 6 ++++++ README.md | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/README.Rmd b/README.Rmd index 8e8b5fd7..07d75c96 100644 --- a/README.Rmd +++ b/README.Rmd @@ -155,6 +155,12 @@ adsl %>% xportr_write("adsl.xpt") ``` +Furthermore, if you're calling all xportr functions at once with common metadata and verbosity, you can shorten it by simply using `xportr()`. + +```{r, warning=FALSE, message=FALSE, eval=FALSE} +xportr(adsl, var_spec, dataset_spec, "ADSL", verbose = "warn", "adsl.xpt") +``` + That's it! We now have a xpt file created in R with all appropriate types, lengths, labels, ordering and formats. Please check out the [Get Started](https://atorus-research.github.io/xportr/articles/xportr.html) for more information and detailed walk through of each `xportr_` function. We are in talks with other Pharma companies involved with the [`{pharmaverse}`](https://pharmaverse.org/) to enhance this package to play well with other downstream and upstream packages. diff --git a/README.md b/README.md index 6546d5b1..9d84dc0f 100644 --- a/README.md +++ b/README.md @@ -165,6 +165,13 @@ adsl %>% xportr_write("adsl.xpt") ``` +Furthermore, if you’re calling all xportr functions at once with common +metadata and verbosity, you can shorten it by simply using `xportr()`. + +``` r +xportr(adsl, var_spec, dataset_spec, "ADSL", verbose = "warn", "adsl.xpt") +``` + That’s it! We now have a xpt file created in R with all appropriate types, lengths, labels, ordering and formats. Please check out the [Get Started](https://atorus-research.github.io/xportr/articles/xportr.html) From 0e1a305d9fb3faf78133da174a60b51d25fe167d Mon Sep 17 00:00:00 2001 From: EeethB Date: Thu, 1 Feb 2024 10:29:08 -0600 Subject: [PATCH 25/26] Add argument names to `xportr()` in README --- README.Rmd | 7 ++++++- README.md | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.Rmd b/README.Rmd index 07d75c96..fc74cc11 100644 --- a/README.Rmd +++ b/README.Rmd @@ -158,7 +158,12 @@ adsl %>% Furthermore, if you're calling all xportr functions at once with common metadata and verbosity, you can shorten it by simply using `xportr()`. ```{r, warning=FALSE, message=FALSE, eval=FALSE} -xportr(adsl, var_spec, dataset_spec, "ADSL", verbose = "warn", "adsl.xpt") +xportr(.df = adsl, + var_metadata = var_spec, + df_metadata = dataset_spec, + domain = "ADSL", + verbose = "warn", + "adsl.xpt") ``` That's it! We now have a xpt file created in R with all appropriate types, lengths, labels, ordering and formats. Please check out the [Get Started](https://atorus-research.github.io/xportr/articles/xportr.html) for more information and detailed walk through of each `xportr_` function. diff --git a/README.md b/README.md index 9d84dc0f..b4533ce5 100644 --- a/README.md +++ b/README.md @@ -169,7 +169,12 @@ Furthermore, if you’re calling all xportr functions at once with common metadata and verbosity, you can shorten it by simply using `xportr()`. ``` r -xportr(adsl, var_spec, dataset_spec, "ADSL", verbose = "warn", "adsl.xpt") +xportr(.df = adsl, + var_metadata = var_spec, + df_metadata = dataset_spec, + domain = "ADSL", + verbose = "warn", + "adsl.xpt") ``` That’s it! We now have a xpt file created in R with all appropriate From 8f5fc66bbf2b620fb0d8bf3879aab3fd0c075437 Mon Sep 17 00:00:00 2001 From: EeethB Date: Thu, 1 Feb 2024 10:37:18 -0600 Subject: [PATCH 26/26] Run styler --- README.Rmd | 14 ++++++++------ README.md | 14 ++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/README.Rmd b/README.Rmd index fc74cc11..8b71800d 100644 --- a/README.Rmd +++ b/README.Rmd @@ -158,12 +158,14 @@ adsl %>% Furthermore, if you're calling all xportr functions at once with common metadata and verbosity, you can shorten it by simply using `xportr()`. ```{r, warning=FALSE, message=FALSE, eval=FALSE} -xportr(.df = adsl, - var_metadata = var_spec, - df_metadata = dataset_spec, - domain = "ADSL", - verbose = "warn", - "adsl.xpt") +xportr( + .df = adsl, + var_metadata = var_spec, + df_metadata = dataset_spec, + domain = "ADSL", + verbose = "warn", + "adsl.xpt" +) ``` That's it! We now have a xpt file created in R with all appropriate types, lengths, labels, ordering and formats. Please check out the [Get Started](https://atorus-research.github.io/xportr/articles/xportr.html) for more information and detailed walk through of each `xportr_` function. diff --git a/README.md b/README.md index b4533ce5..e64b19ed 100644 --- a/README.md +++ b/README.md @@ -169,12 +169,14 @@ Furthermore, if you’re calling all xportr functions at once with common metadata and verbosity, you can shorten it by simply using `xportr()`. ``` r -xportr(.df = adsl, - var_metadata = var_spec, - df_metadata = dataset_spec, - domain = "ADSL", - verbose = "warn", - "adsl.xpt") +xportr( + .df = adsl, + var_metadata = var_spec, + df_metadata = dataset_spec, + domain = "ADSL", + verbose = "warn", + "adsl.xpt" +) ``` That’s it! We now have a xpt file created in R with all appropriate