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

Remove dynamic domain determination #193

Merged
merged 21 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 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
5 changes: 2 additions & 3 deletions R/length.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +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 [xportr_domain_name()] or
#' [xportr_metadata()] must be called before hand to set the domain as an
#' attribute of `.df`.
#' 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
32 changes: 9 additions & 23 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,12 +36,14 @@
#' library(magrittr)
#'
#' adlb %>%
#' xportr_domain_name("adlb") %>%
#' xportr_metadata(metadata, "test") %>%
#' xportr_type() %>%
#' xportr_order()
#' }
xportr_metadata <- function(.df, metadata, domain = NULL) {
xportr_metadata <- function(.df, metadata = NULL, domain = NULL) {
if (is.null(metadata) && is.null(domain)) {
stop("Must provide either metadata or domain argument")

Check warning on line 45 in R/metadata.R

View check run for this annotation

Codecov / codecov/patch

R/metadata.R#L45

Added line #L45 was not covered by tests
elimillera marked this conversation as resolved.
Show resolved Hide resolved
}
## Common section to detect domain from argument or attribute

domain <- get_domain(.df, domain)
Expand All @@ -50,20 +53,3 @@

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


#' Update Metadata Domain Name
#'
#' Similar to `xportr_metadata()`, but just adds 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) {
attr(.df, "_xportr.df_arg_") <- domain

.df
}
2 changes: 1 addition & 1 deletion R/support-test.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ multiple_vars_in_spec_helper2 <- function(FUN) {
local_cli_theme()

adsl %>%
xportr_domain_name("adsl") %>%
xportr_metadata(domain = "adsl") %>%
FUN(metadata) %>%
testthat::expect_no_message(message = "There are multiple specs for the same variable name")
}
1 change: 0 additions & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ reference:
- xportr_order
- xportr_df_label
- xportr_metadata
- xportr_domain_name

- title: xportr helper functions
desc: Utility functions called within core xportr functions
Expand Down
24 changes: 8 additions & 16 deletions man/metadata.Rd

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

5 changes: 2 additions & 3 deletions man/xportr_df_label.Rd

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

5 changes: 2 additions & 3 deletions man/xportr_format.Rd

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

5 changes: 2 additions & 3 deletions man/xportr_label.Rd

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

5 changes: 2 additions & 3 deletions man/xportr_length.Rd

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

5 changes: 2 additions & 3 deletions man/xportr_order.Rd

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

5 changes: 2 additions & 3 deletions man/xportr_type.Rd

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

5 changes: 2 additions & 3 deletions man/xportr_write.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/test-length.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test_that("xportr_length: Accepts valid domain names in metadata object", {

# Test minimal call with valid data and without domain
adsl %>%
xportr_domain_name("adsl") %>%
xportr_metadata(domain = "adsl") %>%
xportr_length(metadata) %>%
expect_silent() %>%
expect_attr_width(metadata$length)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ test_that("xportr_df_label: Correctly applies label when data is piped", {
df_meta <- data.frame(dataset = "df", label = "Label")

df_spec_labeled_df <- df %>%
xportr_domain_name("df") %>%
xportr_metadata(domain = "df") %>%
xportr_df_label(df_meta) %>%
xportr_df_label(df_meta)

Expand Down Expand Up @@ -621,7 +621,7 @@ test_that("xportr_*: Domain is kept in between calls", {
)

df2 <- adsl %>%
xportr_domain_name("adsl") %>%
xportr_metadata(domain = "adsl") %>%
xportr_type(metadata)

df3 <- df2 %>%
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-order.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test_that("xportr_order: Variable are ordered correctly when data is piped", {

ordered_df <- suppressMessages(
df %>%
xportr_domain_name("df") %>%
xportr_metadata(domain = "df") %>%
xportr_order(df_meta) %>%
xportr_order(df_meta)
)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-type.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ test_that("xportr_type: Variables retain column attributes, besides class", {
withr::local_message_sink(tempfile())

df_type_label <- adsl %>%
xportr_domain_name("adsl") %>%
xportr_metadata(domain = "adsl") %>%
xportr_type(metadata) %>%
xportr_label(metadata) %>%
xportr_length(metadata) %>%
xportr_format(metadata)

df_label_type <- adsl %>%
xportr_domain_name("adsl") %>%
xportr_metadata(domain = "adsl") %>%
xportr_label(metadata) %>%
xportr_length(metadata) %>%
xportr_format(metadata) %>%
Expand Down
Loading