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 #137 - Add xportr_process() to apply all and write #200

Merged
merged 32 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
63c5b7b
Add `verbose` option to metadata
EeethB Jan 8, 2024
18c766f
Add verbose to metadata
EeethB Nov 28, 2023
c96d4df
Update docs
EeethB Dec 6, 2023
f6a644b
Add basic top-level wrapper
EeethB Dec 11, 2023
21accf0
Add docs for xportr()
EeethB Jan 8, 2024
9afeeb5
Correct failing tests
EeethB Jan 9, 2024
f7cf129
Run styler
EeethB Jan 9, 2024
2d8dcb3
Merge latest from non-dynamic domain branch
EeethB Jan 10, 2024
0dc0a83
Correct typo in `xportr()` to pass test
EeethB Jan 10, 2024
88b0c5e
Document
EeethB Jan 10, 2024
226f434
Update xportr() example to use internal data
EeethB Jan 11, 2024
517c84a
Style
EeethB Jan 11, 2024
e883121
Add `xportr()` to pkgdown reference
EeethB Jan 11, 2024
1d024b6
Merge branch 'main' into 137_apply_all_write
bms63 Jan 16, 2024
f67e9c7
Merge latest metadata changes from 151
EeethB Jan 18, 2024
63beadf
Streamline documentation
EeethB Jan 20, 2024
a729e5c
Streamline documentation
EeethB Jan 20, 2024
c122df6
Adjust magrittr-conditional example
EeethB Jan 22, 2024
b4a50ca
Update metadata tests to remove unnecessary messaging
EeethB Jan 22, 2024
5a7f78b
Update `xportr()` tests to remove unnecessary messaging
EeethB Jan 22, 2024
5e723be
Update `xportr()` tests to remove unnecessary messaging
EeethB Jan 22, 2024
d0bc225
Update temp files to use `local_file()`
EeethB Jan 22, 2024
4eea166
Update temp files to use `local_file()`
EeethB Jan 22, 2024
e2f7e25
Fix unmatched paren in tests
EeethB Jan 22, 2024
1e992a9
Remove duplicate comment
EeethB Jan 22, 2024
065097f
Fix error in test file path
EeethB Jan 22, 2024
caf21da
Merge branch 'main' into 137_apply_all_write
averissimo Jan 25, 2024
9540747
Merge 151 to correct failing tests
EeethB Jan 29, 2024
5d971f2
Add `xportr()` to README
EeethB Jan 29, 2024
8e1c7fe
Merge branch 'main' into 137_apply_all_write
bms63 Jan 29, 2024
0e1a305
Add argument names to `xportr()` in README
EeethB Feb 1, 2024
8f5fc66
Run styler
EeethB Feb 1, 2024
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: 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
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
* It is now possible to get and set the xportr options using the helper function `xportr_options()` (#130)
* Adds argument assertions to public functions using `{checkmate}` (#175)

EeethB marked this conversation as resolved.
Show resolved Hide resolved
* `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)

* All core functions can be run together by using new function `xportr()` (#137)

## Documentation

## Deprecation and Breaking Changes

* The `domain` argument for xportr functions will no longer be dynamically
Expand Down
6 changes: 3 additions & 3 deletions R/format.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions R/length.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +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`
#'
Expand Down
1 change: 1 addition & 0 deletions R/xportr-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
#'
#'
#' @keywords internal
#' @aliases xportr-package
#'
#' @import rlang haven
#' @importFrom dplyr left_join bind_cols filter select rename rename_with n
Expand Down
69 changes: 69 additions & 0 deletions R/xportr.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#' 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
averissimo marked this conversation as resolved.
Show resolved Hide resolved
#'
#' @return Returns the input dataframe invisibly
#' @export
#'
EeethB marked this conversation as resolved.
Show resolved Hide resolved
#' @examplesIf requireNamespace("magrittr")
#' library(magrittr)
#' 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"
#'
#' 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 <- function(.df,
var_metadata = NULL,
df_metadata = NULL,
domain = NULL,
verbose = NULL,
path,
strict_checks = FALSE) {
.df %>%
xportr_metadata(var_metadata, domain = domain, verbose = verbose) %>%
xportr_type() %>%
xportr_length() %>%
xportr_label() %>%
xportr_order() %>%
xportr_format() %>%
xportr_df_label(df_metadata) %>%
xportr_write(path)
}
8 changes: 7 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ 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}
EeethB marked this conversation as resolved.
Show resolved Hide resolved
```{r, warning=FALSE, message=FALSE, eval=FALSE}
adsl %>%
xportr_metadata(var_spec, "ADSL", verbose = "warn") %>%
xportr_type() %>%
Expand All @@ -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")
```
EeethB marked this conversation as resolved.
Show resolved Hide resolved

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.
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ each function call.

``` r
adsl %>%
xportr_metadata(var_spec, "ADSL") %>%
xportr_metadata(var_spec, "ADSL", verbose = "warn") %>%
xportr_type() %>%
xportr_length() %>%
xportr_label() %>%
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions man/metadata.Rd

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

2 changes: 1 addition & 1 deletion man/xportr-package.Rd

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

79 changes: 79 additions & 0 deletions man/xportr.Rd

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

4 changes: 2 additions & 2 deletions man/xportr_df_label.Rd

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

10 changes: 5 additions & 5 deletions man/xportr_format.Rd

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

4 changes: 2 additions & 2 deletions man/xportr_label.Rd

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

4 changes: 2 additions & 2 deletions man/xportr_length.Rd

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

2 changes: 1 addition & 1 deletion man/xportr_options.Rd

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

4 changes: 2 additions & 2 deletions man/xportr_order.Rd

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

4 changes: 2 additions & 2 deletions man/xportr_type.Rd

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

4 changes: 2 additions & 2 deletions man/xportr_write.Rd

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

Loading
Loading