diff --git a/vignettes/xpt_validate.png b/man/figures/xpt_validate.png similarity index 100% rename from vignettes/xpt_validate.png rename to man/figures/xpt_validate.png diff --git a/vignettes/deepdive.Rmd b/vignettes/deepdive.Rmd index ce8f8915..f521a5cf 100644 --- a/vignettes/deepdive.Rmd +++ b/vignettes/deepdive.Rmd @@ -88,8 +88,7 @@ The `xpt` Version 5 files form the backbone of any successful Submission and are Each of the core `{xportr}` functions for applying labels, types, formats, order and lengths provides feedback to users on submission compliance. However, a final check is implemented when `xportr_write()` is called to create the `xpt`. `xportr_write()` calls [`xpt_validate()`](https://github.com/atorus-research/xportr/blob/231e959b84aa0f1e71113c85332de33a827e650a/R/utils-xportr.R#L174), which is a behind the scenes/non-exported function that does a final check for compliance. At the time of `{xportr} v0.3.0` we are checking the following when a user writes out an `xpt` file.: -validate - +validate # {xportr} in action @@ -295,10 +294,7 @@ var_spec_lbl <- var_spec %>% adsl_lbl <- adsl -adsl_lbl[] <- lapply(adsl_lbl, function(x) { - attributes(x) <- NULL - x -}) +adsl_lbl <- haven::zap_label(adsl) ``` We have successfully removed all the labels. diff --git a/vignettes/xportr.Rmd b/vignettes/xportr.Rmd index 263df4d4..1fab926b 100644 --- a/vignettes/xportr.Rmd +++ b/vignettes/xportr.Rmd @@ -22,6 +22,7 @@ options(cli.num_colors = 1) ``` ```{r, include=FALSE} +options(width = 60) local({ hook_output <- knitr::knit_hooks$get("output") knitr::knit_hooks$set(output = function(x, options) { @@ -36,6 +37,24 @@ local({ }) ``` + +```{r, include=FALSE} + +knitr::knit_hooks$set(output = function(x, options){ + if(!is.null(options$max_height)){ + paste('
', 
+          x, "
", + sep = "") + } else{ + x + } + +}) + +``` + # Getting Started with xportr The demo will make use of a small `ADSL` data set that is apart of the [`{admiral}`](https://pharmaverse.github.io/admiral/index.html) package. @@ -118,7 +137,7 @@ DT::datatable(var_spec_view, options = list( In order to be compliant with transport v5 specifications an `xpt` file can only have two data types: character and numeric/dbl. Currently the `ADSL` data set has chr, dbl, time, factor and date. -```{r, max.height='300px', attr.output='.numberLines', echo = FALSE} +```{r, max_height = "200px", echo = FALSE} str(adsl) ``` @@ -133,7 +152,7 @@ adsl_type <- xportr_type(adsl, var_spec, domain = "ADSL", verbose = "message") Now all appropriate types have been applied to the dataset as seen below. -```{r, max.height='300px', attr.output='.numberLines', echo = FALSE} +```{r, max_height = "200px", echo = FALSE} str(adsl_type) ``` @@ -141,7 +160,7 @@ str(adsl_type) Next we can apply the lengths from a variable level specification file to the data frame. `xportr_length()` will identify variables that are missing from your specification file. The function will also alert you to how many lengths have been applied successfully. Before we apply the lengths lets verify that no lengths have been applied to the original dataframe. -```{r, max.height='300px', attr.output='.numberLines', echo = FALSE} +```{r, max_height = "200px", echo = FALSE} str(adsl) ``` @@ -152,7 +171,7 @@ adsl_length <- adsl %>% xportr_length(var_spec, domain = "ADSL", "message") ``` -```{r, max.height='300px', attr.output='.numberLines', echo = TRUE} +```{r, max_height = "200px", echo = FALSE} str(adsl_length) ``` @@ -178,11 +197,18 @@ DT::datatable(adsl_order, options = list( Now we apply formats to the dataset. These will typically be `DATE9.`, `DATETIME20` or `TIME5`, but many others can be used. Notice that in the `ADSL` dataset there are 8 Date/Time variables and they are missing formats. Here we just take a peak at a few `TRT` variables, which have a `NULL` format. -```{r} -attr(adsl$TRTSDT, "format.sas") -attr(adsl$TRTEDT, "format.sas") -attr(adsl$TRTSDTM, "format.sas") -attr(adsl$TRTEDTM, "format.sas") +```{r, max_height = "200px", echo = FALSE} +adsl_fmt_pre <- adsl %>% + select(TRTSDT, TRTEDT, TRTSDTM, TRTEDTM) + +tribble( + ~Variable, ~Format, + "TRTSDT", attr(adsl_fmt_pre$TRTSDT, which = "format"), + "TRTEDT", attr(adsl_fmt_pre$TRTEDT, which = "format"), + "TRTSDTM", attr(adsl_fmt_pre$TRTSDTM, which = "format"), + "TRTEDTM", attr(adsl_fmt_pre$TRTEDTM, which = "format") + ) + ``` Using our `xportr_format()` we can apply our formats to the dataset. @@ -191,19 +217,28 @@ Using our `xportr_format()` we can apply our formats to the dataset. adsl_fmt <- adsl %>% xportr_format(var_spec, domain = "ADSL", "message") ``` -```{r} -attr(adsl_fmt$TRTSDT, "format.sas") -attr(adsl_fmt$TRTEDT, "format.sas") -attr(adsl_fmt$TRTSDTM, "format.sas") -attr(adsl_fmt$TRTEDTM, "format.sas") +```{r, max_height = "200px", echo = FALSE} +adsl_fmt_post <- adsl_fmt %>% + select(TRTSDT, TRTEDT, TRTSDTM, TRTEDTM) + +tribble( + ~Variable, ~Format, + "TRTSDT", attr(adsl_fmt_post$TRTSDT, which = "format"), + "TRTEDT", attr(adsl_fmt_post$TRTEDT, which = "format"), + "TRTSDTM", attr(adsl_fmt_post$TRTSDTM, which = "format"), + "TRTEDTM", attr(adsl_fmt_post$TRTEDTM, which = "format") + ) + ``` # xportr_label() Please observe that our `ADSL` dataset is missing many variable labels. Sometimes these labels can be lost while using R's function. However, a CDISC compliant data set needs to have each variable with a label. -```{r, max.height='300px', attr.output='.numberLines', echo = TRUE} -str(adsl) +```{r, max_height = "200px", echo = FALSE} +adsl_no_lbls <- haven::zap_label(adsl) + +str(adsl_no_lbls) ``` Using the `xport_label` function we can take the specifications file and label all the variables available. `xportr_label` will produce a warning message if you the variable in the data set is not in the specification file. @@ -212,7 +247,7 @@ Using the `xport_label` function we can take the specifications file and label a adsl_lbl <- adsl %>% xportr_label(var_spec, domain = "ADSL", "message") ``` -```{r, max.height='300px', attr.output='.numberLines', echo = TRUE} +```{r, max_height = "200px"} str(adsl_lbl) ```