Skip to content

Commit

Permalink
docs: #84 scrollable checks, moved png
Browse files Browse the repository at this point in the history
  • Loading branch information
bms63 committed Jun 15, 2023
1 parent bd40b2e commit aeac637
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 23 deletions.
File renamed without changes
8 changes: 2 additions & 6 deletions vignettes/deepdive.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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.:

<img src="xpt_validate.png" alt="validate" style="width: calc(100% - 2px); padding: 0; margin: 0;"/>

<img src="../man/figures/xpt_validate.png" alt="validate" style="width: calc(100% - 2px); padding: 0; margin: 0;"/>

# {xportr} in action

Expand Down Expand Up @@ -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.
Expand Down
69 changes: 52 additions & 17 deletions vignettes/xportr.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -36,6 +37,24 @@ local({
})
```


```{r, include=FALSE}
knitr::knit_hooks$set(output = function(x, options){
if(!is.null(options$max_height)){
paste('<pre style = "max-height:',
options$max_height,
'; float: left; width: 775px; overflow-y: auto;">',
x, "</pre>",
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.
Expand Down Expand Up @@ -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)
```

Expand All @@ -133,15 +152,15 @@ 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)
```

# xportr_length()

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)
```

Expand All @@ -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)
```

Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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)
```

Expand Down

0 comments on commit aeac637

Please sign in to comment.