Skip to content

Commit

Permalink
Merge branch 'main' into 175-assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
averissimo authored Jan 16, 2024
2 parents 5ab7ed5 + bcf4c88 commit 1242d08
Show file tree
Hide file tree
Showing 41 changed files with 593 additions and 484 deletions.
114 changes: 45 additions & 69 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,86 +1,62 @@
Package: xportr
Title: Utilities to Output CDISC SDTM/ADaM XPT Files
Version: 0.3.1.9000
Authors@R:
c(
person(given = "Eli",
family = "Miller",
role = c("aut", "cre"),
email = "[email protected]",
Version: 0.3.1.9007
Authors@R: c(
person("Eli", "Miller", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-2127-9456")),
person(given = "Vignesh ",
family = "Thanikachalam",
role = c("aut")),
person(given = "Ben",
family = "Straub",
role = ("aut")),
person(given = "Ross",
family = "Didenko",
role = ("aut")),
person(given = "Zelos",
family = "Zhu",
role = ("aut")),
person(given = "Ethan",
family = "Brockmann",
role = ("aut")),
person(given = "Vedha",
family = "Viyash",
role = ("aut")),
person(given = "Andre",
family = "Verissimo",
role = ("aut")),
person(given = "Sophie",
family = "Shapcott",
role = ("aut")),
person(given = "Celine",
family = "Piraux",
role = ("aut")),
person(given = "Adrian",
family = "Chan",
role = ("aut")),
person(given = "Sadchla",
family = "Mascary",
role = ("aut")),
person(given = "Atorus/GSK JPT",
role = "cph"))
Description: Tools to build CDISC compliant data sets and check for CDISC compliance.
person("Vignesh ", "Thanikachalam", role = "aut"),
person("Ben", "Straub", role = "aut"),
person("Ross", "Didenko", role = "aut"),
person("Zelos", "Zhu", role = "aut"),
person("Ethan", "Brockmann", role = "aut"),
person("Vedha", "Viyash", role = "aut"),
person("Andre", "Verissimo", role = "aut"),
person("Sophie", "Shapcott", role = "aut"),
person("Celine", "Piraux", role = "aut"),
person("Adrian", "Chan", role = "aut"),
person("Sadchla", "Mascary", role = "aut"),
person("Atorus/GSK JPT", role = "cph")
)
Description: Tools to build CDISC compliant data sets and check for CDISC
compliance.
License: MIT + file LICENSE
URL: https://github.com/atorus-research/xportr
BugReports: https://github.com/atorus-research/xportr/issues
Depends:
R (>= 3.5)
Imports:
checkmate,
cli,

This comment has been minimized.

Copy link
@bms63

bms63 Jan 16, 2024

Collaborator

Do we use cli somewhere? I don't see it?

dplyr (>= 1.0.2),
purrr (>= 0.3.4),
stringr (>= 1.4.0),
magrittr,
glue (>= 1.4.2),
haven (>= 2.5.0),
janitor,
lifecycle,
magrittr,
purrr (>= 0.3.4),
readr,
rlang (>= 0.4.10),
cli,
stringr (>= 1.4.0),
tidyselect,
readr,
janitor,
tm,
haven (>= 2.5.0),
lifecycle
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
tm
Suggests:
testthat (>= 3.0.0),
withr,
knitr,
rmarkdown,
readxl,
DT,
labelled,
admiral,
devtools,
DT,
knitr,
labelled,
lintr,
metacore,
readxl,
rmarkdown,
spelling,
testthat (>= 3.0.0),
usethis,
lintr,
metacore
withr
VignetteBuilder:
knitr
Config/testthat/edition: 3
VignetteBuilder: knitr
Depends:
R (>= 3.5)
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export(type_log)
export(var_names_log)
export(var_ord_msg)
export(xportr_df_label)
export(xportr_domain_name)
export(xportr_format)
export(xportr_label)
export(xportr_length)
Expand Down Expand Up @@ -37,6 +36,7 @@ importFrom(cli,cli_alert_success)
importFrom(cli,cli_div)
importFrom(cli,cli_h2)
importFrom(cli,cli_text)
importFrom(dplyr,across)
importFrom(dplyr,arrange)
importFrom(dplyr,bind_cols)
importFrom(dplyr,case_when)
Expand Down Expand Up @@ -75,6 +75,7 @@ importFrom(stringr,str_replace)
importFrom(stringr,str_replace_all)
importFrom(tidyselect,all_of)
importFrom(tidyselect,any_of)
importFrom(tidyselect,where)
importFrom(tm,stemDocument)
importFrom(utils,capture.output)
importFrom(utils,packageVersion)
Expand Down
15 changes: 14 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,24 @@

## New Features and Bug Fixes

* `xportr_write()` now accepts `metadata` argument which can be used to set the dataset label to stay consistent with the other `xportr_*` functions. It is noteworthy that the dataset label set using the `xportr_df_label()` function will be retained during the `xportr_write()`.
* Exporting a new dataset `dataset_spec` that contains the Dataset Specification for ADSL. (#179)
* Added a check for character variable lengths up to 200 bytes in `xpt_validate()`(#91, #189).
* File name check is moved to strict_checks condition to allow underscores in the file name. Underscores are allowed in xpt but not per FDA requirements. (#126)
* Adds argument assertions to public functions using `{checkmate}` (#175)

## Deprecation and Breaking Changes

* The `domain` argument for xportr functions will no longer be dynamically
determined by the name of the data frame passed as the .df argument. This was
done to make the use of xportr functions more explicit. (#182)
* The `label` argument from the `xportr_write()` function is deprecated in favor of the `metadata` argument. (#179)
* The `metacore` argument, which was renamed to `metadata` in the following six xportr functions: (`xportr_df_label()`, `xportr_format()`, `xportr_label()`, `xportr_length()`, `xportr_order()`, and `xportr_type()`) in version `0.3.0` with a soft deprecation warning, has now been hard deprecated. Please update your code to use the new `metadata` argument in place of `metacore`.

## Documentation

## Deprecation and Breaking Changes
* Created development version of the website (#187)
* Additional guidance for options added in deep dive vignette (#81)

# xportr 0.3.1

Expand Down
19 changes: 18 additions & 1 deletion R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
#' }
"adsl"

#' Example Dataset Specification
#' Example Dataset Variable Specification
#'
#' @format ## `var_spec`
#' A data frame with 216 rows and 19 columns:
Expand All @@ -82,3 +82,20 @@
#' \item{Developer Notes}{Developer Notes}
#' }
"var_spec"

#' Example Dataset Specification
#'
#' @format ## `dataset_spec`
#' A data frame with 1 row and 9 columns:
#' \describe{
#' \item{Dataset}{<chr> Dataset}
#' \item{Description}{<chr> Dataset description}
#' \item{Class}{<chr> Dataset class}
#' \item{Structure}{<lgl> Logical, indicating if there's a specific structure}
#' \item{Purpose}{<chr> Purpose of the dataset}
#' \item{Key, Variables}{<chr> Join Key variables in the dataset}
#' \item{Repeating}{<chr> Indicates if the dataset is repeating}
#' \item{Reference Data}{<lgl> Regerence Data}
#' \item{Comment}{<chr> Additional comment}
#' }
"dataset_spec"
9 changes: 6 additions & 3 deletions R/df_label.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@ xportr_df_label <- function(.df,
domain = attr(.df, "_xportr.df_arg_"),
metacore = deprecated()) {
if (!missing(metacore)) {
lifecycle::deprecate_warn(
when = "0.3.0",
lifecycle::deprecate_stop(
when = "0.3.1.9005",
what = "xportr_df_label(metacore = )",
with = "xportr_df_label(metadata = )"
)
metadata <- metacore
}
assert_data_frame(.df)
assert_string(domain, null.ok = TRUE)
Expand All @@ -72,6 +71,10 @@ xportr_df_label <- function(.df,
abort("Length of dataset label must be 40 characters or less.")
}

if (stringr::str_detect(label, "[^[:ascii:]]")) {
abort("`label` cannot contain any non-ASCII, symbol or special characters.")
}

attr(.df, "label") <- label

.df
Expand Down
7 changes: 3 additions & 4 deletions R/format.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ xportr_format <- function(.df,
domain = attr(.df, "_xportr.df_arg_"),
metacore = deprecated()) {
if (!missing(metacore)) {
lifecycle::deprecate_warn(
when = "0.3.0",
lifecycle::deprecate_stop(
when = "0.3.1.9005",
what = "xportr_format(metacore = )",
with = "xportr_format(metadata = )"
)
metadata <- metacore
}
assert_data_frame(.df)
assert_string(domain, null.ok = TRUE)
Expand All @@ -65,7 +64,7 @@ xportr_format <- function(.df,

if (inherits(metadata, "Metacore")) metadata <- metadata$var_spec

if (domain_name %in% names(metadata)) {
if (domain_name %in% names(metadata) && !is.null(domain)) {
metadata <- metadata %>%
dplyr::filter(!!sym(domain_name) == domain & !is.na(!!sym(format_name)))
} else {
Expand Down
7 changes: 3 additions & 4 deletions R/label.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,11 @@ xportr_label <- function(.df,
verbose = getOption("xportr.label_verbose", "none"),
metacore = deprecated()) {
if (!missing(metacore)) {
lifecycle::deprecate_warn(
when = "0.3.0",
lifecycle::deprecate_stop(
when = "0.3.1.9005",
what = "xportr_label(metacore = )",
with = "xportr_label(metadata = )"
)
metadata <- metacore
}
assert_data_frame(.df)
assert_string(domain, null.ok = TRUE)
Expand All @@ -82,7 +81,7 @@ xportr_label <- function(.df,

if (inherits(metadata, "Metacore")) metadata <- metadata$var_spec

if (domain_name %in% names(metadata)) {
if (domain_name %in% names(metadata) && !is.null(domain)) {
metadata <- metadata %>%
dplyr::filter(!!sym(domain_name) == domain)
} else {
Expand Down
11 changes: 5 additions & 6 deletions R/length.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#' @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 name of the dataset passed as
#' .df will be used.
#' 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'
Expand Down Expand Up @@ -69,12 +69,11 @@ xportr_length <- function(.df,
verbose = getOption("xportr.length_verbose", "none"),
metacore = deprecated()) {
if (!missing(metacore)) {
lifecycle::deprecate_warn(
when = "0.3.0",
lifecycle::deprecate_stop(
when = "0.3.1.9005",
what = "xportr_length(metacore = )",
with = "xportr_length(metadata = )"
)
metadata <- metacore
}
assert_data_frame(.df)
assert_string(domain, null.ok = TRUE)
Expand All @@ -89,7 +88,7 @@ xportr_length <- function(.df,

if (inherits(metadata, "Metacore")) metadata <- metadata$var_spec

if (domain_name %in% names(metadata)) {
if (domain_name %in% names(metadata) && !is.null(domain)) {
metadata <- metadata %>%
filter(!!sym(domain_name) == domain)
} else {
Expand Down
38 changes: 12 additions & 26 deletions R/metadata.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#' Set variable specifications and domain
#'
#' Sets metadata for a dataset in a way that can be accessed by other xportr
#' functions. If used at the start of an xportr pipeline, it removes the need to
#' set metadata and domain at each step individually. For details on the format
#' of the metadata, see the 'Metadata' section for each function in question.
#' Sets metadata and/or domain for a dataset in a way that can be accessed by
#' other xportr functions. If used at the start of an xportr pipeline, it
#' removes the need to set metadata and domain at each step individually. For
#' details on the format of the metadata, see the 'Metadata' section for each
#' function in question.
#'
#' @inheritParams xportr_length
#'
Expand Down Expand Up @@ -35,36 +36,21 @@
#' library(magrittr)
#'
#' adlb %>%
#' xportr_domain_name("adlb") %>%
#' xportr_metadata(metadata, "test") %>%
#' xportr_type() %>%
#' xportr_order()
#' }
xportr_metadata <- function(.df, metadata, domain = attr(.df, "_xportr.df_arg_")) {
xportr_metadata <- function(.df, metadata = NULL, domain = NULL) {
assert_data_frame(.df)
assert_metadata(metadata, include_fun_message = FALSE)
if (is.null(metadata) && is.null(domain)) {
stop("Assertion failed on `metadata` and `domain`: Must provide either `metadata` or `domain` argument")
}
assert_metadata(metadata, include_fun_message = FALSE, null.ok = TRUE)
assert_string(domain, null.ok = TRUE)

## Common section to detect domain from argument or attribute

if (!is.null(domain)) .df <- xportr_domain_name(.df, domain)

structure(.df, "_xportr.df_metadata_" = metadata)
}


#' Update Metadata Domain Name
#'
#' Similar to `xportr_metadata`, but just added the domain and not the metadata.
#'
#' @inheritParams xportr_length
#'
#' @return `.df` dataset with domain argument set
#' @export
#'
#' @rdname metadata
xportr_domain_name <- function(.df, domain) {
assert_data_frame(.df)
assert_string(domain)
attr(.df, "_xportr.df_arg_") <- domain

.df
}
Loading

0 comments on commit 1242d08

Please sign in to comment.