Skip to content

Commit

Permalink
Add docs for xportr()
Browse files Browse the repository at this point in the history
  • Loading branch information
EeethB committed Jan 8, 2024
1 parent badb220 commit 8b46126
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 17 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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_format)
export(xportr_label)
Expand Down
17 changes: 0 additions & 17 deletions R/process.R

This file was deleted.

75 changes: 75 additions & 0 deletions R/xportr.R
Original file line number Diff line number Diff line change
@@ -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)

Check warning on line 74 in R/xportr.R

View check run for this annotation

Codecov / codecov/patch

R/xportr.R#L66-L74

Added lines #L66 - L74 were not covered by tests
}
83 changes: 83 additions & 0 deletions man/xportr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8b46126

Please sign in to comment.