Skip to content

Commit

Permalink
docs: #84 readme update, revert type back
Browse files Browse the repository at this point in the history
  • Loading branch information
bms63 committed Jun 15, 2023
1 parent f8d2800 commit fb7ad19
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
5 changes: 1 addition & 4 deletions R/type.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,8 @@ xportr_type <- function(.df,

## Pull out correct metadata
metadata <- metadata %||%
attr(.df, "_xportr.df_metadata_")

if (is.null(metadata)) {
attr(.df, "_xportr.df_metadata_") %||%
rlang::abort("Metadata must be set with `metadata` or `xportr_metadata()`")
}

if (inherits(metadata, "Metacore")) {
metadata <- metadata$var_spec
Expand Down
21 changes: 10 additions & 11 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ data sets (≤ 200)
- Coerces variables to only numeric or character types
- Display format support for numeric float and date/time values
- Variables names are ≤ 8 characters.
- Variable labels are ≤ 200 characters.
- Variable labels are ≤ 40 characters.
- Data set labels are ≤ 40 characters.
- Presence of non-ASCII characters in Variable Names, Labels or data set labels.

Expand All @@ -103,7 +103,7 @@ To do this we will need to do the following:
- Apply a dataset label
- Write out a version 5 xpt file

All of which can be done using a well-defined specification file and the `xportr` package!
All of which can be done using a well-defined specification file and the `{xportr}` package!

First we will start with our `ADSL` dataset created in R. This example `ADSL` dataset is taken from the [`{admiral}`](https://pharmaverse.github.io/admiral/index.html) package. The script that generates this `ADSL` dataset can be created by using this command `admiral::use_ad_template("adsl")`. This `ADSL` dataset has 306 observations and 48 variables.

Expand All @@ -125,20 +125,19 @@ var_spec <- readxl::read_xlsx(spec_path, sheet = "Variables") %>%
rlang::set_names(tolower)
```

Each `xportr_` function has been written in a way to take in a part of the specification file and apply that piece to the dataset.
Each `xportr_` function has been written in a way to take in a part of the specification file and apply that piece to the dataset. Setting `verbose = "warn"` will send appropriate warning message to the console. We have suppressed the warning for the sake of brevity.

```{r, message=FALSE, eval=FALSE}
```{r, warning = FALSE, message=FALSE, eval=TRUE}
adsl %>%
xportr_metadata(var_spec, "ADSL") %>%
xportr_type() %>%
xportr_length() %>%
xportr_label() %>%
xportr_order() %>%
xportr_format() %>%
xportr_type(var_spec, "ADSL", verbose = "warn") %>%
xportr_length(var_spec, "ADSL", verbose = "warn") %>%
xportr_label(var_spec, "ADSL", verbose = "warn") %>%
xportr_order(var_spec, "ADSL", verbose = "warn") %>%
xportr_format(var_spec, "ADSL", verbose = "warn") %>%
xportr_write("adsl.xpt", label = "Subject-Level Analysis Dataset")
```

The `xportr_metadata()` function can reduce duplication by setting the variable specification and domain explicitly at the top of a pipeline.
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}
adsl %>%
Expand Down
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ to any validators or data reviewers.
- Coerces variables to only numeric or character types
- Display format support for numeric float and date/time values
- Variables names are ≤ 8 characters.
- Variable labels are ≤ 200 characters.
- Variable labels are ≤ 40 characters.
- Data set labels are ≤ 40 characters.
- Presence of non-ASCII characters in Variable Names, Labels or data set
labels.
Expand All @@ -99,7 +99,7 @@ To do this we will need to do the following:
- Write out a version 5 xpt file

All of which can be done using a well-defined specification file and the
`xportr` package!
`{xportr}` package!

First we will start with our `ADSL` dataset created in R. This example
`ADSL` dataset is taken from the
Expand Down Expand Up @@ -131,7 +131,24 @@ var_spec <- readxl::read_xlsx(spec_path, sheet = "Variables") %>%
```

Each `xportr_` function has been written in a way to take in a part of
the specification file and apply that piece to the dataset.
the specification file and apply that piece to the dataset. Setting
`verbose = "warn"` will send appropriate warning message to the console.
We have suppressed the warning for the sake of brevity.

``` r
adsl %>%
xportr_type(var_spec, "ADSL", verbose = "warn") %>%
xportr_length(var_spec, "ADSL", verbose = "warn") %>%
xportr_label(var_spec, "ADSL", verbose = "warn") %>%
xportr_order(var_spec, "ADSL", verbose = "warn") %>%
xportr_format(var_spec, "ADSL", verbose = "warn") %>%
xportr_write("adsl.xpt", label = "Subject-Level Analysis Dataset")
```

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
adsl %>%
Expand Down

0 comments on commit fb7ad19

Please sign in to comment.