Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes 120 - Replace metacore with metadata #134

Merged
merged 14 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ Imports:
readr,
janitor,
tm,
haven (>= 2.5.0)
haven (>= 2.5.0),
lifecycle
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ importFrom(glue,glue)
importFrom(glue,glue_collapse)
importFrom(graphics,stem)
importFrom(janitor,make_clean_names)
importFrom(lifecycle,deprecated)
importFrom(magrittr,"%>%")
importFrom(magrittr,extract2)
importFrom(purrr,map)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

* Moved `{pkgdown}` site to bootswatch. Enabled search and linked slack icon (#122).

## Deprecation and Breaking Changes

* The `metacore` argument has been renamed to `metadata` in the following six xportr functions: `xportr_df_label()`, `xportr_format()`, `xportr_label()`, `xportr_length()`, `xportr_order()`, and `xportr_type()`. Please update your code to use the new `metadata` argument in place of `metacore`.
# xportr 0.2.0
* Added a new validation test that errors when users pass invalid formats (#60 #64). Thanks to @zdz2101!
* Fixed an issue where xportr_format could pass invalid formats to haven::write_xpt.
Expand Down
23 changes: 16 additions & 7 deletions R/df_label.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
#' Assigns dataset label from a dataset level metadata to a given data frame.
#'
#' @param .df A data frame of CDISC standard.
#' @param metacore A data frame containing dataset level metadata.
#' @param metadata A data frame containing dataset level metadata.
#' @param domain A character value to subset the `.df`. If `NULL`(default), uses
#' `.df` value as a subset condition.
#' @param metacore `r lifecycle::badge("deprecated")` Previously used to pass metadata now renamed with `metadata`
#'
#' @return Data frame with label attributes.
#' @family metadata functions
Expand All @@ -26,7 +27,15 @@
#' )
#'
#' adsl <- xportr_df_label(adsl, metadata)
xportr_df_label <- function(.df, metacore = NULL, domain = NULL) {
xportr_df_label <- function(.df, metadata = NULL, domain = NULL, metacore = deprecated()) {
if (!missing(metacore)) {
lifecycle::deprecate_warn(
when = "0.3.0",
what = "xportr_format(metacore = )",
with = "xportr_format(metadata = )"
)
metadata <- metacore
}
domain_name <- getOption("xportr.df_domain_name")
label_name <- getOption("xportr.df_label")

Expand All @@ -39,15 +48,15 @@ xportr_df_label <- function(.df, metacore = NULL, domain = NULL) {
## End of common section

## Pull out correct metadata
metacore <- metacore %||%
metadata <- metadata %||%
attr(.df, "_xportr.df_metadata_") %||%
rlang::abort("Metadata must be set with `metacore` or `xportr_metadata()`")
rlang::abort("Metadata must be set with `metadata` or `xportr_metadata()`")

if (inherits(metacore, "Metacore")) {
metacore <- metacore$ds_spec
if (inherits(metadata, "Metacore")) {
metadata <- metadata$ds_spec
}

label <- metacore %>%
label <- metadata %>%
filter(!!sym(domain_name) == domain) %>%
select(!!sym(label_name)) %>%
# If a dataframe is used this will also be a dataframe, change to character.
Expand Down
32 changes: 23 additions & 9 deletions R/format.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
#' Assigns a SAS format from a variable level metadata to a given data frame.
#'
#' @param .df A data frame of CDISC standard.
#' @param metacore A data frame containing variable level metadata.
#' @param metadata A data frame containing variable level metadata.
#' @param domain A character value to subset the `.df`. If `NULL`(default), uses
#' `.df` value as a subset condition.
#' @param verbose The action the function takes when a variable label isn't.
#' found. Options are 'stop', 'warn', 'message', and 'none'
#' @param metacore `r lifecycle::badge("deprecated")` Previously used to pass metadata now renamed with `metadata`
#'
#' @return Data frame with `SASformat` attributes for each variable.
#' @family metadata functions
Expand All @@ -27,7 +28,20 @@
#' )
#'
#' adsl <- xportr_format(adsl, metadata)
xportr_format <- function(.df, metacore = NULL, domain = NULL, verbose = getOption("xportr.format_verbose", "none")) {
xportr_format <- function(
.df,
metadata = NULL,
domain = NULL,
verbose = getOption("xportr.length_verbose", "none"),
metacore = deprecated()) {
if (!missing(metacore)) {
lifecycle::deprecate_warn(
when = "0.3.0",
what = "xportr_format(metacore = )",
with = "xportr_format(metadata = )"
)
metadata <- metacore
}
domain_name <- getOption("xportr.domain_name")
format_name <- getOption("xportr.format_name")
variable_name <- getOption("xportr.variable_name")
Expand All @@ -40,19 +54,19 @@ xportr_format <- function(.df, metacore = NULL, domain = NULL, verbose = getOpti

## End of common section

metacore <- metacore %||%
metadata <- metadata %||%
attr(.df, "_xportr.df_metadata_") %||%
rlang::abort("Metadata must be set with `metacore` or `xportr_metadata()`")
rlang::abort("Metadata must be set with `metadata` or `xportr_metadata()`")

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

if (domain_name %in% names(metacore)) {
metadata <- metacore %>%
if (domain_name %in% names(metadata)) {
metadata <- metadata %>%
dplyr::filter(!!sym(domain_name) == domain & !is.na(!!sym(format_name)))
} else {
metadata <- metacore
metadata <- metadata
}

filtered_metadata <- metadata %>%
Expand Down
33 changes: 23 additions & 10 deletions R/label.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
#' Assigns variable label from a variable level metadata to a given data frame.
#'
#' @param .df A data frame of CDISC standard.
#' @param metacore A data frame containing variable level metadata.
#' @param metadata A data frame containing variable level metadata.
#' @param domain A character value to subset the `.df`. If `NULL`(default), uses
#' `.df` value as a subset condition.
#' @param verbose The action the function takes when a variable length isn't
#' Found. Options are 'stop', 'warn', 'message', and 'none'
#' @param metacore `r lifecycle::badge("deprecated")` Previously used to pass metadata now renamed with `metadata`
#'
#' @return Data frame with label attributes for each variable.
#' @family metadata functions
Expand All @@ -29,8 +30,20 @@
#' )
#'
#' adsl <- xportr_label(adsl, metadata)
xportr_label <- function(.df, metacore = NULL, domain = NULL,
verbose = getOption("xportr.label_verbose", "none")) {
xportr_label <- function(
.df,
metadata = NULL,
domain = NULL,
verbose = getOption("xportr.length_verbose", "none"),
metacore = deprecated()) {
if (!missing(metacore)) {
lifecycle::deprecate_warn(
when = "0.3.0",
what = "xportr_format(metacore = )",
with = "xportr_format(metadata = )"
)
metadata <- metacore
}
domain_name <- getOption("xportr.domain_name")
variable_name <- getOption("xportr.variable_name")
variable_label <- getOption("xportr.label")
Expand All @@ -43,19 +56,19 @@ xportr_label <- function(.df, metacore = NULL, domain = NULL,

## End of common section

metacore <- metacore %||%
metadata <- metadata %||%
attr(.df, "_xportr.df_metadata_") %||%
rlang::abort("Metadata must be set with `metacore` or `xportr_metadata()`")
rlang::abort("Metadata must be set with `metadata` or `xportr_metadata()`")

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

if (domain_name %in% names(metacore)) {
metadata <- metacore %>%
if (domain_name %in% names(metadata)) {
metadata <- metadata %>%
dplyr::filter(!!sym(domain_name) == domain)
} else {
metadata <- metacore
metadata <- metadata
}


Expand Down
33 changes: 23 additions & 10 deletions R/length.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
#' Assigns SAS length from a variable level metadata to a given data frame.
#'
#' @param .df A data frame of CDISC standard.
#' @param metacore A data frame containing variable level metadata.
#' @param metadata A data frame containing variable level metadata.
#' @param domain A character value to subset the `.df`. If `NULL`(default), uses
#' `.df` value as a subset condition.
#' @param verbose The action the function takes when a length isn't found in
#' metadata. Options are 'stop', 'warn', 'message', and 'none'
#' @param metacore `r lifecycle::badge("deprecated")` Previously used to pass metadata now renamed with `metadata`
#'
#' @return Data frame with `SASlength` attributes for each variable.
#' @family metadata functions
Expand All @@ -27,8 +28,20 @@
#' )
#'
#' adsl <- xportr_length(adsl, metadata)
xportr_length <- function(.df, metacore = NULL, domain = NULL,
verbose = getOption("xportr.length_verbose", "none")) {
xportr_length <- function(
.df,
metadata = NULL,
domain = NULL,
verbose = getOption("xportr.length_verbose", "none"),
metacore = deprecated()) {
if (!missing(metacore)) {
lifecycle::deprecate_warn(
when = "0.3.0",
what = "xportr_format(metacore = )",
with = "xportr_format(metadata = )"
)
metadata <- metacore
}
domain_name <- getOption("xportr.domain_name")
variable_length <- getOption("xportr.length")
variable_name <- getOption("xportr.variable_name")
Expand All @@ -41,19 +54,19 @@ xportr_length <- function(.df, metacore = NULL, domain = NULL,

## End of common section

metacore <- metacore %||%
metadata <- metadata %||%
attr(.df, "_xportr.df_metadata_") %||%
rlang::abort("Metadata must be set with `metacore` or `xportr_metadata()`")
rlang::abort("Metadata must be set with `metadata` or `xportr_metadata()`")

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

if (domain_name %in% names(metacore)) {
metadata <- metacore %>%
if (domain_name %in% names(metadata)) {
metadata <- metadata %>%
filter(!!sym(domain_name) == domain)
} else {
metadata <- metacore
metadata <- metadata
}


Expand Down
32 changes: 23 additions & 9 deletions R/order.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#' Order variables of a dataset according to Spec
#'
#' @param .df A data frame of CDISC standard.
#' @param metacore A data frame containing variable level metadata.
#' @param metadata A data frame containing variable level metadata.
#' @param domain A character value to subset the `.df`. If `NULL`(default), uses
#' `.df` value as a subset condition.
#' @param verbose Option for messaging order results
#' @param metacore `r lifecycle::badge("deprecated")` Previously used to pass metadata now renamed with `metadata`
#'
#' @export
#' @return Dataframe that has been re-ordered according to spec
Expand All @@ -24,7 +25,20 @@
#' )
#'
#' adsl <- xportr_order(adsl, metadata)
xportr_order <- function(.df, metacore = NULL, domain = NULL, verbose = getOption("xportr.order_verbose", "none")) {
xportr_order <- function(
.df,
metadata = NULL,
domain = NULL,
verbose = getOption("xportr.length_verbose", "none"),
metacore = deprecated()) {
if (!missing(metacore)) {
lifecycle::deprecate_warn(
when = "0.3.0",
what = "xportr_format(metacore = )",
with = "xportr_format(metadata = )"
)
metadata <- metacore
}
domain_name <- getOption("xportr.domain_name")
order_name <- getOption("xportr.order_name")
variable_name <- getOption("xportr.variable_name")
Expand All @@ -37,19 +51,19 @@ xportr_order <- function(.df, metacore = NULL, domain = NULL, verbose = getOptio

## End of common section

metacore <- metacore %||%
metadata <- metadata %||%
attr(.df, "_xportr.df_metadata_") %||%
rlang::abort("Metadata must be set with `metacore` or `xportr_metadata()`")
rlang::abort("Metadata must be set with `metadata` or `xportr_metadata()`")

if (inherits(metacore, "Metacore")) {
metacore <- metacore$ds_vars
if (inherits(metadata, "Metacore")) {
metadata <- metadata$ds_vars
}

if (domain_name %in% names(metacore)) {
metadata <- metacore %>%
if (domain_name %in% names(metadata)) {
metadata <- metadata %>%
dplyr::filter(!!sym(domain_name) == domain & !is.na(!!sym(order_name)))
} else {
metadata <- metacore %>%
metadata <- metadata %>%
dplyr::filter(!is.na(!!sym(order_name)))
}

Expand Down
Loading