library(tidyREDCap)
The tidyREDCap
package creates data sets with labelled
columns.
::import_instruments(
tidyREDCapurl = "https://bbmc.ouhsc.edu/redcap/api/",
token = Sys.getenv("REDCapR_test")
)
If you would like to see the labels on the data set
demographics
, you can use the RStudio function
View()
, as shown below.
View(demographics)
However, some functions do not work well with labeled variables.
library(skimr) # for the skim() function
|> skim()
demographics #> Error in `dplyr::summarize()`:
#> ℹ In argument: `skimmed = purrr::map2(...)`.
#> ℹ In group 3: `skim_type = "numeric"`.
#> Caused by error in `purrr::map2()`:
#> ℹ In index: 1.
#> ℹ With name: numeric.
#> Caused by error in `list_unchop()`:
#> ! Can't combine `..1` <double> and `..2` <labelled>.
So you need a way to drop the label off of a variable or to drop all the labels from all the variables in a dataset.
You can drop the label from a single variable with the drop_label() function. For example:
<- drop_label(demographics, "first_name") demographics_changed
You can drop all the labels using the drop_labels()
function. For example:
<- drop_labels(demographics)
demographics_without_labels
|>
demographics_without_labels skim()
Name | demographics_without_labe… |
Number of rows | 5 |
Number of columns | 10 |
_______________________ | |
Column type frequency: | |
character | 7 |
numeric | 3 |
________________________ | |
Group variables | None |
Variable type: character
skim_variable | n_missing | complete_rate | min | max | empty | n_unique | whitespace |
---|---|---|---|---|---|---|---|
name_first | 0 | 1 | 5 | 8 | 0 | 5 | 0 |
name_last | 0 | 1 | 3 | 8 | 0 | 4 | 0 |
address | 0 | 1 | 29 | 38 | 0 | 5 | 0 |
telephone | 0 | 1 | 14 | 14 | 0 | 5 | 0 |
0 | 1 | 12 | 19 | 0 | 5 | 0 | |
sex | 0 | 1 | 4 | 6 | 0 | 2 | 0 |
demographics_complete | 0 | 1 | 8 | 8 | 0 | 1 | 0 |
Variable type: numeric
skim_variable | n_missing | complete_rate | mean | sd | p0 | p25 | p50 | p75 | p100 | hist |
---|---|---|---|---|---|---|---|---|---|---|
record_id | 0 | 1 | 3.0 | 1.58 | 1 | 2 | 3 | 4 | 5 | ▇▇▇▇▇ |
dob | 0 | 1 | -56.0 | 11581.94 | -13051 | -6269 | -5375 | 12121 | 12294 | ▃▇▁▁▇ |
age | 0 | 1 | 44.4 | 31.57 | 11 | 11 | 59 | 61 | 80 | ▇▁▁▇▃ |