diff --git a/.Rbuildignore b/.Rbuildignore index de5a9c5..3ecebbb 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -9,3 +9,4 @@ ^\.travis\.yml$ ^doc$ ^Meta$ +^.github/ \ No newline at end of file diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 0000000..2d19fc7 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml new file mode 100644 index 0000000..ed7650c --- /dev/null +++ b/.github/workflows/pkgdown.yaml @@ -0,0 +1,48 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + release: + types: [published] + workflow_dispatch: + +name: pkgdown + +jobs: + pkgdown: + runs-on: ubuntu-latest + # Only restrict concurrency for non-PR jobs + concurrency: + group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + permissions: + contents: write + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::pkgdown, local::. + needs: website + + - name: Build site + run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) + shell: Rscript {0} + + - name: Deploy to GitHub pages πŸš€ + if: github.event_name != 'pull_request' + uses: JamesIves/github-pages-deploy-action@v4.4.1 + with: + clean: false + branch: gh-pages + folder: docs diff --git a/.gitignore b/.gitignore index 5692018..31f999f 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,7 @@ inst/doc **/.DS_Store doc Meta + +# pkgdown rendering +docs/ +inst/docs/ diff --git a/DESCRIPTION b/DESCRIPTION index 24d8faa..bc27b53 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: tidyREDCap Title: Helper Functions for Working with 'REDCap' Data -Version: 1.1.2 +Version: 1.1.3 Authors@R: c(person( given = "Raymond", @@ -58,8 +58,8 @@ Description: developed at Vanderbilt University. License: MIT + file LICENSE Encoding: UTF-8 -RoxygenNote: 7.3.2 -Depends: R (>= 3.5.0) +RoxygenNote: 7.3.3 +Depends: R (>= 4.1.0) Imports: cli, dplyr, diff --git a/NEWS.md b/NEWS.md index 5c8df42..5f404a9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# tidyREDCap 1.1.3 (CRAN release) + +* Package now depends on R >= 4.1.0 for use of pipe operator. +* Fixed vignette URLs that were causing site redirection issues with automated CRAN checks. +* Added alt text to vignette images. + # tidyREDCap 1.1.2 (CRAN release) * Fix issues reported by CRAN with Linux and old R Windows (4.3.3) saying diff --git a/R/make_instrument_auto.R b/R/make_instrument_auto.R index 43af055..3270e23 100644 --- a/R/make_instrument_auto.R +++ b/R/make_instrument_auto.R @@ -13,20 +13,24 @@ #' @export #' ## @examples -make_instrument_auto <- function(df, drop_which_when = FALSE, - record_id = "record_id") { +make_instrument_auto <- function( + df, + drop_which_when = FALSE, + record_id = "record_id" +) { if (names(df)[1] != record_id) { - stop(" + stop( + " The first variable in df must be `record_id`; - use option 'record_id=' to set the name of your custom id.", call. = FALSE) + use option 'record_id=' to set the name of your custom id.", + call. = FALSE + ) } - # Strip labels from REDCap created variables to prevent reported join (and # perhaps pivot) issues on labeled variables. df <- drop_label(df, record_id) - is_longitudinal <- any(names(df) == "redcap_event_name") if (is_longitudinal) { @@ -69,37 +73,49 @@ make_instrument_auto <- function(df, drop_which_when = FALSE, record_id_col <- which(colnames(df) == record_id) redcap_event_name_col <- which(colnames(df) == "redcap_event_name") record_repeat_inst_col <- which(colnames(df) == "redcap_repeat_instance") - + if (is_longitudinal) { - # Select rows that have data with a repeat number - if (is_repeated & !all(is.na(df[!allMissing,record_repeat_inst_col]))) { - return(df[!allMissing, c( - record_id_col, - redcap_event_name_col, - record_repeat_inst_col, - first_col:last_col - )]) + # Select rows that have data with a repeat number + if (is_repeated & !all(is.na(df[!allMissing, record_repeat_inst_col]))) { + return(df[ + !allMissing, + c( + record_id_col, + redcap_event_name_col, + record_repeat_inst_col, + first_col:last_col + ) + ]) } else { # Longitudinal not repeated instruments - return(df[!allMissing, c( - record_id_col, - redcap_event_name_col, - first_col:last_col - )]) + return(df[ + !allMissing, + c( + record_id_col, + redcap_event_name_col, + first_col:last_col + ) + ]) } } else { - # Select rows that have data with a repeat number - if (is_repeated & !all(is.na(df[!allMissing,record_repeat_inst_col]))) { - return(df[!allMissing, c( - record_id_col, - record_repeat_inst_col, - first_col:last_col - )]) + # Select rows that have data with a repeat number + if (is_repeated & !all(is.na(df[!allMissing, record_repeat_inst_col]))) { + return(df[ + !allMissing, + c( + record_id_col, + record_repeat_inst_col, + first_col:last_col + ) + ]) } else { - return(df[!allMissing, c( - record_id_col, - first_col:last_col - )]) + return(df[ + !allMissing, + c( + record_id_col, + first_col:last_col + ) + ]) } } } else { @@ -157,19 +173,43 @@ fix_class_bug <- function(df) { "fix_class_bug" -#' Drop the label from a variable -#' @description There is a reported issues with joins on data (without a reprex) -#' that seem to be caused by the labels. As a possible solution this can be -#' used to drop labels. +#' Drop the label from one or more variables +#' @description There is a reported issue with joins on data (without a reprex) +#' that seem to be caused by the labels. As a possible solution this can be +#' used to drop labels from one or more variables. #' #' @param df the name of the data frame -#' @param x the quoted name of the variable +#' @param ... Variable selection using tidyselect helpers (e.g., `contains()`, +#' `starts_with()`) or column names as symbols or strings #' -#' @export +#' @examples +#' \dontrun{ +#' # Remove labels from a single variable +#' df |> drop_label(employment) #' +#' # Remove labels from multiple variables +#' df |> drop_label(employment, marital_status) #' -#' @return df -drop_label <- function(df, x) { - attributes(df[, which(names(df) == x)]) <- NULL +#' # Remove all demograhic labels using tidyselect helpers +#' df |> drop_label(starts_with("dem_")) +#' } +#' +#' @export +#' +#' @return df with labels removed from selected variables +drop_label <- function(df, ...) { + # Capture the variables using tidyselect + vars_idx <- tidyselect::eval_select(rlang::expr(c(...)), df) + + # If no variables selected, return the dataframe as is + if (length(vars_idx) == 0) return(df) + + # For each selected column, remove its attributes + for (col_idx in vars_idx) { + attributes(df[[col_idx]]) <- NULL + } + + # TODO: investigate if labelled class needs to be dropped + df } diff --git a/docs/404.html b/docs/404.html deleted file mode 100644 index 90992db..0000000 --- a/docs/404.html +++ /dev/null @@ -1,140 +0,0 @@ - - - - - - - -Page not found (404) β€’ tidyREDCap - - - - - - - - - - - - - - - - - - -
-
- - - - -
-
- - -Content not found. Please use links in the navbar. - -
- - - -
- - - - -
- - - - - - - - diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html deleted file mode 100644 index 09b9e7f..0000000 --- a/docs/LICENSE-text.html +++ /dev/null @@ -1,107 +0,0 @@ - -License β€’ tidyREDCap - - -
-
- - - -
-
- - -
YEAR: 2020
-COPYRIGHT HOLDER: Raymond Balise
-
- -
- - - -
- - - -
- - - - - - - - diff --git a/docs/LICENSE.html b/docs/LICENSE.html deleted file mode 100644 index b7bd1d4..0000000 --- a/docs/LICENSE.html +++ /dev/null @@ -1,111 +0,0 @@ - -MIT License β€’ tidyREDCap - - -
-
- - - -
-
- - -
- -

Copyright (c) 2020 Raymond Balise

-

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the β€œSoftware”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

-

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

-

THE SOFTWARE IS PROVIDED β€œAS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

-
- -
- - - -
- - - -
- - - - - - - - diff --git a/docs/apple-touch-icon-120x120.png b/docs/apple-touch-icon-120x120.png deleted file mode 100644 index bdc1373..0000000 Binary files a/docs/apple-touch-icon-120x120.png and /dev/null differ diff --git a/docs/apple-touch-icon-152x152.png b/docs/apple-touch-icon-152x152.png deleted file mode 100644 index f7dc9c4..0000000 Binary files a/docs/apple-touch-icon-152x152.png and /dev/null differ diff --git a/docs/apple-touch-icon-180x180.png b/docs/apple-touch-icon-180x180.png deleted file mode 100644 index 59f864c..0000000 Binary files a/docs/apple-touch-icon-180x180.png and /dev/null differ diff --git a/docs/apple-touch-icon-60x60.png b/docs/apple-touch-icon-60x60.png deleted file mode 100644 index 94c8c5b..0000000 Binary files a/docs/apple-touch-icon-60x60.png and /dev/null differ diff --git a/docs/apple-touch-icon-76x76.png b/docs/apple-touch-icon-76x76.png deleted file mode 100644 index 8cc5a5f..0000000 Binary files a/docs/apple-touch-icon-76x76.png and /dev/null differ diff --git a/docs/apple-touch-icon.png b/docs/apple-touch-icon.png deleted file mode 100644 index a993216..0000000 Binary files a/docs/apple-touch-icon.png and /dev/null differ diff --git a/docs/articles/dashboard.jpg b/docs/articles/dashboard.jpg deleted file mode 100644 index 04a217a..0000000 Binary files a/docs/articles/dashboard.jpg and /dev/null differ diff --git a/docs/articles/dropLabels.html b/docs/articles/dropLabels.html deleted file mode 100644 index a4f8d33..0000000 --- a/docs/articles/dropLabels.html +++ /dev/null @@ -1,620 +0,0 @@ - - - - - - - -Drop Labels from a Table β€’ tidyREDCap - - - - - - - - - - - - - - - - - - - -
-
- - - - -
-
- - - - - -
-

The Problem -

-

The tidyREDCap package creates data sets with labelled -columns.

-
-tidyREDCap::import_instruments(
-  url = "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
-demographics |> skim()
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Data summary
Namedemographics
Number of rows5
Number of columns10
_______________________
Column type frequency:
character7
Date1
numeric2
________________________
Group variablesNone
-

Variable type: character

- ---------- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
skim_variablen_missingcomplete_rateminmaxemptyn_uniquewhitespace
name_first0158050
name_last0138040
address012938050
telephone011414050
email011219050
sex0146020
demographics_complete0188010
-

Variable type: Date

- --------- - - - - - - - - - - - - - - - - - - -
skim_variablen_missingcomplete_rateminmaxmediann_unique
dob011934-04-092003-08-301955-04-155
-

Variable type: numeric

- ------------- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
skim_variablen_missingcomplete_ratemeansdp0p25p50p75p100hist
record_id013.01.5812345β–‡β–‡β–‡β–‡β–‡
age0144.431.571111596180▇▁▁▇▃
-

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.

-
-
-

The Solution -

-

You can drop the label from a single variable with the drop_label() -function. For example:

-
-demographics_changed <- drop_label(demographics, "first_name")
-

You can drop all the labels using the drop_labels() -function. For example:

-
-demographics_without_labels <- drop_labels(demographics)
-
-demographics_without_labels |> 
-  skim()
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Data summary
Namedemographics_without_labe…
Number of rows5
Number of columns10
_______________________
Column type frequency:
character7
numeric3
________________________
Group variablesNone
-

Variable type: character

- ---------- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
skim_variablen_missingcomplete_rateminmaxemptyn_uniquewhitespace
name_first0158050
name_last0138040
address012938050
telephone011414050
email011219050
sex0146020
demographics_complete0188010
-

Variable type: numeric

- ------------- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
skim_variablen_missingcomplete_ratemeansdp0p25p50p75p100hist
record_id013.01.5812345β–‡β–‡β–‡β–‡β–‡
dob01-56.011581.94-13051-6269-53751212112294▃▇▁▁▇
age0144.431.571111596180▇▁▁▇▃
-
-
- - - -
- - - - -
- - - - - - - - diff --git a/docs/articles/global.jpg b/docs/articles/global.jpg deleted file mode 100644 index 795fb27..0000000 Binary files a/docs/articles/global.jpg and /dev/null differ diff --git a/docs/articles/hama.jpg b/docs/articles/hama.jpg deleted file mode 100644 index a04601d..0000000 Binary files a/docs/articles/hama.jpg and /dev/null differ diff --git a/docs/articles/import_instruments.html b/docs/articles/import_instruments.html deleted file mode 100644 index a8a9b7c..0000000 --- a/docs/articles/import_instruments.html +++ /dev/null @@ -1,219 +0,0 @@ - - - - - - - -Import All Instruments from a REDCap Project β€’ tidyREDCap - - - - - - - - - - - - - - - - - - - -
-
- - - - -
-
- - - - - - -
-

The Problem -

-Suppose you have a REDCap project with many instruments; some -instruments are administered in some visits but not in others. In that -case, the export from REDCap will have empty cells for the visits in -which the instrument was not used. For example, Figure 1 shows a study -where subjects completed four instruments (Enrollment, NCI, GAD7, and -Hamilton) at baseline. On days 1, 2, and 3, they completed only -Hamilton. At the end of the study, they completed NCI and Hamilton. The -export of the data for this subject will have five records (one for each -visit), and each record will have a cell for every existing instrument. -However, the β€œNCI” record will only have values for the baseline and -final visit and empty cells for the visits in between. On the other -hand, there will be no empty spaces for the β€œHamilton” record as it was -completed in all the visits. It would be good to have a function that -will export all the data from a project and produce one R table for each -instrument. Those tables should remove the blank records.

-Figure 1 -

-

The same functionality should help deal with instruments that are -potentially given repeatedly. Common examples include asking -participants to fill out a form describing medical conditions for all -their siblings or asking them to fill out a form for each side effect -they experience while using a drug. In these cases, each participant may -have zero or many records. Again, creating a table with all the records -for these β€œrepeated” instruments would be good.

-
-
-

The Solution -

-
-# Do not type your API token directly into your code
-tidyREDCap::import_instruments(
-  url = "https://redcap.miami.edu/api/",
-  token = "1A2B3CXXYYZZOOMMGOSHNOOOOX1Y2Z3" # This is BAD!
-)
-
-# A better way to do this is to read the API key from the .Renviron file.
-#   For instructions on saving your API key, see link below.
-tidyREDCap::import_instruments(
-  url = "https://redcap.miami.edu/api/", 
-  token = Sys.getenv("nacho_anxiety_key")  # This is BETTER!
-)
-

See the Importing from REDCap -vignette for details/information for saving your API key in the -.Renviron file.

-

The import_instruments() function can be given a URL and -token for a REDCap project, like the one created above and it will -return one table for each instrument in a project. By default, the -function will drop all empty records. For example, the above API call is -pulling data from a REDCap project that has four instruments: -Enrollment, the Nacho Craving Index (NCI), the Generalized Anxiety -Disorder Assessment (GAD7), and the Hamilton Anxiety Scale (HAM-A).

-

After running the above code we get four tables from the REDCap -project.

-

-

Notice that each repeat of the HAM-A is its own record.

-

-

If a person has only done the baseline assessment they will only have -one record.

-
-
- - - -
- - - - -
- - - - - - - - diff --git a/docs/articles/index.html b/docs/articles/index.html deleted file mode 100644 index c1f4fc3..0000000 --- a/docs/articles/index.html +++ /dev/null @@ -1,116 +0,0 @@ - -Articles β€’ tidyREDCap - - -
-
- - - -
- -
- - -
- - - - - - - - diff --git a/docs/articles/key.jpg b/docs/articles/key.jpg deleted file mode 100644 index 5f4441c..0000000 Binary files a/docs/articles/key.jpg and /dev/null differ diff --git a/docs/articles/makeBinaryWord.html b/docs/articles/makeBinaryWord.html deleted file mode 100644 index 95b0bde..0000000 --- a/docs/articles/makeBinaryWord.html +++ /dev/null @@ -1,455 +0,0 @@ - - - - - - - -Make Binary Word β€’ tidyREDCap - - - - - - - - - - - - - - - - - - - -
-
- - - - -
-
- - - - - -

-
-

The Problem -

-

REDCap exports a β€œchoose all that apply” question into a series of -similarly-named, binary indicator variables (i.e., the variables are -equal to either β€œchecked” or β€œunchecked”). Using these variables -individually, there is no obvious way to detect common patterns people -pick together.

-
-

Example: In the Nacho Craving Index (NCI), -respondents can indicate which of eight ingredients they are currently -craving (i.e., Chips, Yellow cheese, Orange cheese, White cheese, Meat, -Beans, Tomatoes, Peppers). These are exported into variables with names -like ingredients___1, ingredients___2, -etc.

-
-

In REDCap, it is simple to get a summary of those individual -variables by using the β€œData Exports, Reports, and Stats” application -within the REDCap interface and selecting β€œStats & Charts”. Once the -data is in R, simple tables can be produced with the -table() function, or beautiful tables can be created with -the tabyl() and adorn_pct_formatting() -functions from the janitor package. However, from these -univariate tables, it is impossible to judge which patterns of answers -are marked together. In the above example, using the univariate tables, -it is difficult to tell what percentage of people are craving both chips -and yellow cheese.

-
-redcap <- readRDS(file = "./redcap.rds")
-
-# Chips
-janitor::tabyl(redcap$ingredients___1) %>% 
-  janitor::adorn_pct_formatting() %>% 
-  knitr::kable()
- - - - - - - - - - - - - - - - - - -
redcap$ingredients___1npercent
Unchecked2170.0%
Checked930.0%
-
-
-# Yellow cheese
-janitor::tabyl(redcap$ingredients___2) %>% 
-  janitor::adorn_pct_formatting() %>% 
-  knitr::kable()
- - - - - - - - - - - - - - - - - - -
redcap$ingredients___2npercent
Unchecked2376.7%
Checked723.3%
-
-

Aside: Loading REDCap Data into R -

-

See the Import All -Instruments from a REDCap Project and Importing from REDCap vignettes for -details/information.

-
-
-
-

Make Analysis Data -

-

Even after subsetting the REDCap data to only include the ingredients -variables, it is still difficult to detect common patterns in the eight -ingredients.

-
-redcap <- readRDS(file = "./redcap.rds")
-
-analysis <- redcap %>% 
-  select(starts_with("ingredients___")) 
-  
-knitr::kable(tail(analysis))
- ----------- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ingredients___1ingredients___2ingredients___3ingredients___4ingredients___5ingredients___6ingredients___7ingredients___8
25CheckedCheckedUncheckedUncheckedUncheckedCheckedUncheckedUnchecked
26UncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUnchecked
27UncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUnchecked
28UncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUnchecked
29UncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUnchecked
30CheckedCheckedUncheckedUncheckedUncheckedUncheckedCheckedUnchecked
-

-
-
-

The Solution -

-
-

Default Lettering -

-

The make_binary_word() function combines responses from -the individual variables into a single β€œword” that indicates which -choices were selected. For example, if the first option from the NCI -ingredient question, chips (i.e., -ingredients___1), was checked, the word created by -make_binary_word() will begin with a; or if it was -not checked, the word would start with _. If the second option, -Yellow cheese (i.e., ingredients___2), was -checked, the next letter will be a b; otherwise, a _ -will be used as a placeholder. Following this pattern, if somebody is -not craving any of the eight nacho ingredients, the β€œword” will be eight -underscores, one for each ingredient (i.e., ________). Conversely, if -they are craving every ingredient, the β€œword” will be -abcdefgh.

-
-patterns <- make_binary_word(analysis) 
-janitor::tabyl(patterns)
-#>  patterns  n    percent
-#>  ________ 20 0.66666667
-#>  ______gh  1 0.03333333
-#>  a_c__f_h  1 0.03333333
-#>  a_cdefgh  1 0.03333333
-#>  ab____g_  1 0.03333333
-#>  ab___f__  1 0.03333333
-#>  ab___f_h  1 0.03333333
-#>  ab__efgh  1 0.03333333
-#>  ab_de_gh  1 0.03333333
-#>  ab_defgh  1 0.03333333
-#>  abcdef_h  1 0.03333333
-
-
-

Custom Lettering -

-

While the default lettering is somewhat helpful, using meaningful -(mnemonic) letters makes the binary words easier to understand. In this -case, the first letter for each choice can be used as a helpful -mnemonic.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AbbreviationIngredient
CChips
YYellow cheese
OOrange cheese
WWhite cheese
MMeat
BBeans
TTomatoes
PPeppers
-

To use custom lettering, specify a vector of single-letter -abbreviations and pass it to the the_labels argument. Be -sure to include one unique abbreviation for each data frame column. For -example:

-
-labels <- c("C", "Y", "O", "W", "M", "B", "T", "P")
-
-patterns <- make_binary_word(analysis, the_labels = labels)
-
-janitor::tabyl(patterns)
-#>  patterns  n    percent
-#>  CYOWMB_P  1 0.03333333
-#>  CY_WMBTP  1 0.03333333
-#>  CY_WM_TP  1 0.03333333
-#>  CY__MBTP  1 0.03333333
-#>  CY___B_P  1 0.03333333
-#>  CY___B__  1 0.03333333
-#>  CY____T_  1 0.03333333
-#>  C_OWMBTP  1 0.03333333
-#>  C_O__B_P  1 0.03333333
-#>  ______TP  1 0.03333333
-#>  ________ 20 0.66666667
-

The summary table shows that 20 people did not provide information -about what ingredients they craved. The remaining people do not display -any recurring patterns, but many people craved chips and yellow cheese -together.

-
-
-
- - - -
- - - - -
- - - - - - - - diff --git a/docs/articles/makeBinaryWord_files/accessible-code-block-0.0.1/empty-anchor.js b/docs/articles/makeBinaryWord_files/accessible-code-block-0.0.1/empty-anchor.js deleted file mode 100644 index ca349fd..0000000 --- a/docs/articles/makeBinaryWord_files/accessible-code-block-0.0.1/empty-anchor.js +++ /dev/null @@ -1,15 +0,0 @@ -// Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> -// v0.0.1 -// Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. - -document.addEventListener('DOMContentLoaded', function() { - const codeList = document.getElementsByClassName("sourceCode"); - for (var i = 0; i < codeList.length; i++) { - var linkList = codeList[i].getElementsByTagName('a'); - for (var j = 0; j < linkList.length; j++) { - if (linkList[j].innerHTML === "") { - linkList[j].setAttribute('aria-hidden', 'true'); - } - } - } -}); diff --git a/docs/articles/makeBinaryWord_files/header-attrs-2.6.4/header-attrs.js b/docs/articles/makeBinaryWord_files/header-attrs-2.6.4/header-attrs.js deleted file mode 100644 index dd57d92..0000000 --- a/docs/articles/makeBinaryWord_files/header-attrs-2.6.4/header-attrs.js +++ /dev/null @@ -1,12 +0,0 @@ -// Pandoc 2.9 adds attributes on both header and div. We remove the former (to -// be compatible with the behavior of Pandoc < 2.8). -document.addEventListener('DOMContentLoaded', function(e) { - var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); - var i, h, a; - for (i = 0; i < hs.length; i++) { - h = hs[i]; - if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 - a = h.attributes; - while (a.length > 0) h.removeAttribute(a[0].name); - } -}); diff --git a/docs/articles/makeChooseAllTable.html b/docs/articles/makeChooseAllTable.html deleted file mode 100644 index 35c5f61..0000000 --- a/docs/articles/makeChooseAllTable.html +++ /dev/null @@ -1,282 +0,0 @@ - - - - - - - -Make a 'Choose All' Table β€’ tidyREDCap - - - - - - - - - - - - - - - - - - - -
-
- - - - -
-
- - - - - -

-
-

The Problem -

-

REDCap exports a β€œchoose all that apply” question into a series of -similarly-named, binary indicator variables (i.e., the variables are -equal to either β€œchecked” or β€œunchecked”). For example, the following -data represents a sample of responses to the Nacho Craving Index.

-
-redcap <- readRDS(file = "./redcap.rds")
-redcap %>% 
-  select(starts_with("ingredients___")) %>% 
-  head()
-#>   ingredients___1 ingredients___2 ingredients___3 ingredients___4
-#> 1         Checked         Checked         Checked         Checked
-#> 2         Checked         Checked       Unchecked         Checked
-#> 3       Unchecked       Unchecked       Unchecked       Unchecked
-#> 4       Unchecked       Unchecked       Unchecked       Unchecked
-#> 5       Unchecked       Unchecked       Unchecked       Unchecked
-#> 6       Unchecked       Unchecked       Unchecked       Unchecked
-#>   ingredients___5 ingredients___6 ingredients___7 ingredients___8
-#> 1         Checked         Checked       Unchecked         Checked
-#> 2         Checked       Unchecked         Checked         Checked
-#> 3       Unchecked       Unchecked       Unchecked       Unchecked
-#> 4       Unchecked       Unchecked       Unchecked       Unchecked
-#> 5       Unchecked       Unchecked       Unchecked       Unchecked
-#> 6       Unchecked       Unchecked       Unchecked       Unchecked
-

It is desirable to have a concise table showing how often each option -was chosen.

-
-

Aside: Loading REDCap Data into R -

-

See the Import All -Instruments from a REDCap Project and Importing from REDCap vignettes for -details/information.

-
-
-
-

The Solution -

-
-

Data Loaded with import_instruments() -

-

If you pass the make_choose_all_table() function, the -name of a REDCap export, and the name of the choose all that apply -question question in REDCap, it will produce a concise frequency -count table.

-
-make_choose_all_table(redcap, "ingredients") 
-#> # A tibble: 8 Γ— 2
-#>   What          Count
-#>   <chr>         <dbl>
-#> 1 Chips             9
-#> 2 Yellow cheese     7
-#> 3 Orange cheese     3
-#> 4 White cheese      4
-#> 5 Meat              5
-#> 6 Beans             7
-#> 7 Tomatoes          6
-#> 8 Peppers           8
-

Similar to the make_choose_one_table() function, we can -use this function inside an analysis pipeline. We can add the -kable() call to make the table publication quality.

-
-redcap %>% 
-  make_choose_all_table("ingredients") %>% 
-  knitr::kable()
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
WhatCount
Chips9
Yellow cheese7
Orange cheese3
White cheese4
Meat5
Beans7
Tomatoes6
Peppers8
-
-
-

Data Exported with β€œData Exports, Reports and Stats” in REDCap -

-

If you export data using the point-and-click tools built into REDCap -you end up with two files, one contains R code the other data. When you -run the code you end up with a dataset called data which -contains two copies of some of the information. For example, if you -download the Nacho Craving Index you will see the ingredients variables, -showing what ingredients people are craving, and a second copy of the -variables that have .factor tagged to the end of the names. -The factor versions do not have the variable labels. So you will need to -subset the data to drop them. The example below shows the process. Note -we have copied the data data frame to have a more -meaningful name.

-
-# This is the data produced by exporting using point-and-click REDCap export.
-manual_export <- data
-
-manual_export |>   
-  select(starts_with("ingredient")) |> # get all the ingredient variables
-  select(-ends_with(".factor")) |>     # drop the factor version of the ingredient variables
-  make_choose_all_table("ingredient")  # make the table
-
-
-
- - - -
- - - - -
- - - - - - - - diff --git a/docs/articles/makeChooseAllTable_files/accessible-code-block-0.0.1/empty-anchor.js b/docs/articles/makeChooseAllTable_files/accessible-code-block-0.0.1/empty-anchor.js deleted file mode 100644 index ca349fd..0000000 --- a/docs/articles/makeChooseAllTable_files/accessible-code-block-0.0.1/empty-anchor.js +++ /dev/null @@ -1,15 +0,0 @@ -// Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> -// v0.0.1 -// Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. - -document.addEventListener('DOMContentLoaded', function() { - const codeList = document.getElementsByClassName("sourceCode"); - for (var i = 0; i < codeList.length; i++) { - var linkList = codeList[i].getElementsByTagName('a'); - for (var j = 0; j < linkList.length; j++) { - if (linkList[j].innerHTML === "") { - linkList[j].setAttribute('aria-hidden', 'true'); - } - } - } -}); diff --git a/docs/articles/makeChooseAllTable_files/header-attrs-2.6.4/header-attrs.js b/docs/articles/makeChooseAllTable_files/header-attrs-2.6.4/header-attrs.js deleted file mode 100644 index dd57d92..0000000 --- a/docs/articles/makeChooseAllTable_files/header-attrs-2.6.4/header-attrs.js +++ /dev/null @@ -1,12 +0,0 @@ -// Pandoc 2.9 adds attributes on both header and div. We remove the former (to -// be compatible with the behavior of Pandoc < 2.8). -document.addEventListener('DOMContentLoaded', function(e) { - var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); - var i, h, a; - for (i = 0; i < hs.length; i++) { - h = hs[i]; - if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 - a = h.attributes; - while (a.length > 0) h.removeAttribute(a[0].name); - } -}); diff --git a/docs/articles/makeChooseOneTable.html b/docs/articles/makeChooseOneTable.html deleted file mode 100644 index eb4e5fc..0000000 --- a/docs/articles/makeChooseOneTable.html +++ /dev/null @@ -1,289 +0,0 @@ - - - - - - - -Make a 'Choose One' Table β€’ tidyREDCap - - - - - - - - - - - - - - - - - - - -
-
- - - - -
-
- - - - - -

-
-

The Problem -

-

It is often desirable to print variable labels above a summary table -that shows the count of factor labels. The labels exported on choose -all that apply questions, including the question and whichever -response was chosen. This redundancy is often unwanted, and the results -are not presented professionally.

-

For example, in the Nacho Craving Index data, the first ingredient is -β€œChips”. We see how R presents this information by simply printing the -components of the ingredients___1 column.

-
-redcap <- readRDS(file = "./redcap.rds")
-redcap$ingredients___1
-# What ingredients do you currently crave?: Chips
-#  [1] Checked   Checked   Unchecked Unchecked Unchecked Unchecked Checked  
-#  [8] Unchecked Unchecked Unchecked Unchecked Unchecked Checked   Unchecked
-# [15] Unchecked Checked   Unchecked Unchecked Checked   Unchecked Unchecked
-# [22] Unchecked Checked   Unchecked Checked   Unchecked Unchecked Unchecked
-# [29] Unchecked Checked  
-# attr(,"redcapLabels")
-# [1] Unchecked Checked  
-# attr(,"redcapLevels")
-# [1] 0 1
-# Levels: Unchecked Checked
-

As we can see, this information is quite ugly, so we want to tabulate -the results instead. However, if we use the simple table() -function to clean up this information, we lose the original question and -the answer label for ingredients___1.

-
-table(redcap$ingredients___1)
-# 
-# Unchecked   Checked 
-#        21         9
-

We no longer know what the question was or which β€œselect all” option -this information represents.

-
-

Aside: Loading REDCap Data into R -

-

See the Import All -Instruments from a REDCap Project and Importing from REDCap vignettes for -details/information.

-
-
-
-

The Solution -

-

The make_choose_one_table() function can be used with a -factor variable to tabulate the response while preserving the -question and checked option context.

-
-make_choose_one_table(redcap$ingredients___1) 
-# What ingredients do you currently crave?: Chips
-#   Response  n percent
-#  Unchecked 21     70%
-#    Checked  9     30%
-

Further, this output can be molded into a publication-ready table -with a single additional function call.

-
-make_choose_one_table(redcap$ingredients___1) %>% 
-  knitr::kable()
-

What ingredients do you currently crave?: Chips

- - - - - - - - - - - - - - - - - - -
Responsenpercent
Unchecked2170%
Checked930%
-

The subset option, if set to TRUE, will -cause the function to remove the label’s text and only show the response -option (i.e., not repeat the β€œWhat ingredients do you currently crave?” -question).

-
-make_choose_one_table(
-  redcap$ingredients___2,
-  subset = TRUE
-) %>% 
-  knitr::kable()
-

Yellow cheese

- - - - - - - - - - - - - - - - - - -
Responsenpercent
Unchecked2377%
Checked723%
-

This function can also be used in an analysis pipeline with a data -frame name and the name of the factor inside that data frame. For -example:

-
-redcap %>% 
-  make_choose_one_table(ingredients___3) %>% 
-  knitr::kable() 
-

What ingredients do you currently crave?: Orange cheese

- - - - - - - - - - - - - - - - - - -
Responsenpercent
Unchecked2790%
Checked310%
-
-
- - - -
- - - - -
- - - - - - - - diff --git a/docs/articles/makeChooseOneTable_files/accessible-code-block-0.0.1/empty-anchor.js b/docs/articles/makeChooseOneTable_files/accessible-code-block-0.0.1/empty-anchor.js deleted file mode 100644 index ca349fd..0000000 --- a/docs/articles/makeChooseOneTable_files/accessible-code-block-0.0.1/empty-anchor.js +++ /dev/null @@ -1,15 +0,0 @@ -// Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> -// v0.0.1 -// Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. - -document.addEventListener('DOMContentLoaded', function() { - const codeList = document.getElementsByClassName("sourceCode"); - for (var i = 0; i < codeList.length; i++) { - var linkList = codeList[i].getElementsByTagName('a'); - for (var j = 0; j < linkList.length; j++) { - if (linkList[j].innerHTML === "") { - linkList[j].setAttribute('aria-hidden', 'true'); - } - } - } -}); diff --git a/docs/articles/makeChooseOneTable_files/header-attrs-2.6.4/header-attrs.js b/docs/articles/makeChooseOneTable_files/header-attrs-2.6.4/header-attrs.js deleted file mode 100644 index dd57d92..0000000 --- a/docs/articles/makeChooseOneTable_files/header-attrs-2.6.4/header-attrs.js +++ /dev/null @@ -1,12 +0,0 @@ -// Pandoc 2.9 adds attributes on both header and div. We remove the former (to -// be compatible with the behavior of Pandoc < 2.8). -document.addEventListener('DOMContentLoaded', function(e) { - var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); - var i, h, a; - for (i = 0; i < hs.length; i++) { - h = hs[i]; - if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 - a = h.attributes; - while (a.length > 0) h.removeAttribute(a[0].name); - } -}); diff --git a/docs/articles/makeInstrument.html b/docs/articles/makeInstrument.html deleted file mode 100644 index f2236f8..0000000 --- a/docs/articles/makeInstrument.html +++ /dev/null @@ -1,682 +0,0 @@ - - - - - - - -Make an Instrument β€’ tidyREDCap - - - - - - - - - - - - - - - - - - - -
-
- - - - -
-
- - - - - -

-
-

The Problem -

-

REDCap exports longitudinal projects with one record (a line of data) -per assessment (typically 1 line per day). This works well when every -instrument/questionnaire is given at every assessment. Still, for -projects with different instruments/questionnaires given on different -days, REDCap exports empty values (represented by the value -NA in R).

-
-

Example: In the Nachos for Anxiety project, three -instruments were used; they each had a different administration -schedule. Subjects’ anxiety was assessed at baseline with the -Generalized Anxiety Disorder 7-item (GAD-7) scale. Every day, it was -assessed with the Hamilton Anxiety Scale (HAM-A), but the Nacho Craving -Index was administered only at the baseline and at the end of the study -(see the figure below for clarification).

-
-

The instruments that are not assessed every day appear as entirely -blank questionnaires when the data is exported. For example, values from -the NCI instrument are shown as missing for Day 1, Day 2, and Day 3 -(because it was not administered during those visits).

-

In R, this data is displayed as

-
-redcap <- readRDS(file = "./redcap_nacho_anxiety.rds")
-
-redcap %>% 
-  select(
-    # Select these two columns
-    record_id, redcap_event_name,
-    # And also select all columns between "nachos" and "nci_complete"
-    nachos:nci_complete
-  ) %>% 
-  # Make the table pretty
-  knitr::kable()
- ----------------------------- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
record_idredcap_event_namenachostreattreatingotherconditionlasttraveledmilesnowstrongingredients___1ingredients___2ingredients___3ingredients___4ingredients___5ingredients___6ingredients___7ingredients___8cheesecrunchbeanguacamolejalapenomeatlifenci_complete
1baseline_arm_1YesTRUEOtherAnxietyI ate nachos in the last year.Yes3115Yes74CheckedCheckedUncheckedCheckedCheckedCheckedCheckedChecked5 Love it5 Love it5 Love it5 Love it5 Love it5 Love itThey helped me cure my hunger.Complete
1day_1_arm_1NANANANANANANANANANANANANANANANANANANANANANANANANA
1day_2_arm_1NANANANANANANANANANANANANANANANANANANANANANANANANA
1day_3_arm_1NANANANANANANANANANANANANANANANANANANANANANANANANA
1end_arm_1YesTRUEOtherAnxietyI am currently eating nachos.Yes3115Yes90CheckedCheckedCheckedCheckedCheckedCheckedCheckedChecked5 Love it5 Love it5 Love it5 Love it5 Love it5 Love itThey make me feel happy.Complete
-

It is often helpful to make a different data table that has the -values for each questionnaire without the blank records.

-
-

Aside: Loading REDCap Data into R -

-

See the Import All -Instruments from a REDCap Project and Importing from REDCap vignettes for -details/information.

-
-
-
-

The Solution -

-

Pass the make_instrument() function to the name of a -dataset and the names of the first and last variables in an instrument, -and it will return a table that has the non-empty records for the -instrument. For example, to extract the enrollment/consent -instrument:

-
-make_instrument(redcap, "concented", "enrollment_complete") %>% 
-  knitr::kable()
- - - - - - - - - - - - - -
record_idredcap_event_nameconcentedenrollment_complete
1baseline_arm_1YesComplete
-

To extract nacho craving information:

-
-make_instrument(redcap, "nachos", "nci_complete") %>% 
-  knitr::kable()
- ------------------------------ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
record_idredcap_event_namenachostreattreatingotherconditionlasttraveledmilesnowstrongingredients___1ingredients___2ingredients___3ingredients___4ingredients___5ingredients___6ingredients___7ingredients___8cheesecrunchbeanguacamolejalapenomeatlifenci_complete
11baseline_arm_1YesTRUEOtherAnxietyI ate nachos in the last year.Yes3115Yes74CheckedCheckedUncheckedCheckedCheckedCheckedCheckedChecked5 Love it5 Love it5 Love it5 Love it5 Love it5 Love itThey helped me cure my hunger.Complete
51end_arm_1YesTRUEOtherAnxietyI am currently eating nachos.Yes3115Yes90CheckedCheckedCheckedCheckedCheckedCheckedCheckedChecked5 Love it5 Love it5 Love it5 Love it5 Love it5 Love itThey make me feel happy.Complete
-

To make an analysis dataset containing the NCI values -without the subject ID and the event name:

-
-make_instrument(
-  redcap,
-  "nachos", "nci_complete",
-  drop_which_when = TRUE
-) %>% 
-  knitr::kable()
- ---------------------------- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
nachostreattreatingotherconditionlasttraveledmilesnowstrongingredients___1ingredients___2ingredients___3ingredients___4ingredients___5ingredients___6ingredients___7ingredients___8cheesecrunchbeanguacamolejalapenomeatlifenci_complete
1YesTRUEOtherAnxietyI ate nachos in the last year.Yes3115Yes74CheckedCheckedUncheckedCheckedCheckedCheckedCheckedChecked5 Love it5 Love it5 Love it5 Love it5 Love it5 Love itThey helped me cure my hunger.Complete
5YesTRUEOtherAnxietyI am currently eating nachos.Yes3115Yes90CheckedCheckedCheckedCheckedCheckedCheckedCheckedChecked5 Love it5 Love it5 Love it5 Love it5 Love it5 Love itThey make me feel happy.Complete
-
-
- - - -
- - - - -
- - - - - - - - diff --git a/docs/articles/makeInstrument_files/accessible-code-block-0.0.1/empty-anchor.js b/docs/articles/makeInstrument_files/accessible-code-block-0.0.1/empty-anchor.js deleted file mode 100644 index ca349fd..0000000 --- a/docs/articles/makeInstrument_files/accessible-code-block-0.0.1/empty-anchor.js +++ /dev/null @@ -1,15 +0,0 @@ -// Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> -// v0.0.1 -// Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. - -document.addEventListener('DOMContentLoaded', function() { - const codeList = document.getElementsByClassName("sourceCode"); - for (var i = 0; i < codeList.length; i++) { - var linkList = codeList[i].getElementsByTagName('a'); - for (var j = 0; j < linkList.length; j++) { - if (linkList[j].innerHTML === "") { - linkList[j].setAttribute('aria-hidden', 'true'); - } - } - } -}); diff --git a/docs/articles/makeInstrument_files/header-attrs-2.6.4/header-attrs.js b/docs/articles/makeInstrument_files/header-attrs-2.6.4/header-attrs.js deleted file mode 100644 index dd57d92..0000000 --- a/docs/articles/makeInstrument_files/header-attrs-2.6.4/header-attrs.js +++ /dev/null @@ -1,12 +0,0 @@ -// Pandoc 2.9 adds attributes on both header and div. We remove the former (to -// be compatible with the behavior of Pandoc < 2.8). -document.addEventListener('DOMContentLoaded', function(e) { - var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); - var i, h, a; - for (i = 0; i < hs.length; i++) { - h = hs[i]; - if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 - a = h.attributes; - while (a.length > 0) h.removeAttribute(a[0].name); - } -}); diff --git a/docs/articles/schedule.png b/docs/articles/schedule.png deleted file mode 100644 index d86eeb6..0000000 Binary files a/docs/articles/schedule.png and /dev/null differ diff --git a/docs/articles/useAPI.html b/docs/articles/useAPI.html deleted file mode 100644 index 0bc1a3a..0000000 --- a/docs/articles/useAPI.html +++ /dev/null @@ -1,280 +0,0 @@ - - - - - - - -Importing from REDCap β€’ tidyREDCap - - - - - - - - - - - - - - - - - - - -
-
- - - - -
-
- - - - - -
-

Loading REDCap Data into R with an API request -

-

While most people use the β€œData Exports, Reports and Stats” -Application built into REDCap, another handy method to get data out of -REDCap is an API request. An API allows one program to request data from -another program. For example, an add-on package in R can request data -from your instance of REDCap. Obviously, an R package can not -type your user name and password. Instead, you will store an -API token, a password, on your machine and then ask R to look up that -token and pass it to REDCap whenever you want data.

-

We have used two R packages to access our REDCap -projects,redcapAPI and REDCapR. Unfortunately, -redcapAPI is no longer being actively developed, and we -have run into problems with it. It had the lovely benefit of exporting -variables, basically using the same variable names as you see in REDCap, -then tagging the variables with the β€œlabels” subjects viewed when -completing the forms.

-

that people taking REDCap surveys or viewing other forms see.

-

We have taken the labeling functionality and added it in -tidyREDCap.

-
-

Getting an API Token -

-

If your REDCap project has API access enabled, you will see it in the -applications on the left side of the screen.

-

-

If you don’t see that option, talk to your project leader or the -REDCap system administrator.

-

When you click the link you will be given the option to create an API -Token for this project.

-

Once you have that token created, you can copy and paste it somewhere -safe.

-
-
-

Protecting Your API Tokens -

-

Leaders in the REDCap community have developed techniques for safely -storing your REDCap API keys. Ask your REDCap systems administrators how -they prefer you store API keys on your β€œlocal machine”.

-
-
NEVER DO THIS! -
-

The functions that allow you to export data need you to give them -your API token. Remember, this is the same information as your username -and password. NEVER type that directly in your code. -That is if your REDCap API key is β€œ1A2B3CXXYYZZOOMMGOSHNOOOOX1Y2Z3” do -NOT do this:

-
-# Do not type your API token directly into your code
-tidyREDCap::import_instruments(
-  "https://redcap.miami.edu/api/",
-  "1A2B3CXXYYZZOOMMGOSHNOOOOX1Y2Z3" # This is BAD!
-)
-

If you do this, anybody who gets a copy of your code will be able to -access your REDCap project. Also, whenever your run this line of code, -the API token will be saved into your R history files.

-
-
-
Better Options -
-

You can save your API keys into a β€œhidden” file containing code that -runs when you start R. That file is called you β€œ.Renviron”. It can be a -bit of a pain to find. So your best plan is to install the -usethis package, which contains helper functions, including -a function to find this file. If you use the RStudio interface, you can -add it using the Packages window pane or run these lines in the console -once.

-
-install.packages("remotes")
-remotes::install_cran("usethis")
-

When it comes time to add packages to your copy of R, the -install_cran() function in the remotes package -is superior to the usual install.packages() function -because it will first check to see if you already have the latest -version before bothering to download and install.

-

After installing usethis you can access your β€œ.Renviron” -file by typing this in your console.

-
-usethis::edit_r_environ()
-

It will cause the file to open.

-

Create a name for your API key and add a like like this to your -.Renviron file:

-
nacho_anxiety_key="1A2B3CXXYYZZOOMMGOSHNOOOOX1Y2Z3"
-

After adding the line, remember to save the file and completely -restart R/RStudio.

-

Once R restarts, you can access the key like this:

-
-tidyREDCap::import_instruments(
-  "https://redcap.miami.edu/api/", 
-  Sys.getenv("nacho_anxiety_key")
-)
-

If you want to use the redcapAPI or the REDCapR packages directly you -can use the same trickery to pass your API key to their functions. For -example:

-
-rcon <- redcapAPI::redcapConnection(
-  url = 'https://redcap.miami.edu/api/', 
-  token = Sys.getenv("nacho_anxiety_key")
-)
-
-redcap <- redcapAPI::exportRecords(rcon)
-

This includes a call to Sys.getenv() to grab the key. To -learn more about working with APIs, look here.

-

If you are curious, when we made these help files, we saved the data -using the saveRDS() function.

-
-rcon <- redcapAPI::redcapConnection(
-  url = 'https://redcap.miami.edu/api/', 
-  token = Sys.getenv("nacho_anxiety_key")
-)
-
-redcap <- redcapAPI::exportRecords(rcon)
-
-saveRDS(redcap, file = "redcap.rds")
-

-
-
-
-

Even Better Options -

-

If somebody gets access to the files on your machine, they could find -and read your .Renviron file. A more secure option is to use the r -keyring package. It will store an encrypted copy of your -API key in your machine’s credential store (i.e., the β€œkeychain” on -macOS, the Credential Store on Windows, etc.). Consider using it. If you -use it and your machine is stolen, it will buy you more time to find an -internet connection, log into REDCap and change your API tokens (before -the thief can access your data).

-
-
-
- - - -
- - - - -
- - - - - - - - diff --git a/docs/articles/view_demog_w_labels_20230217.png b/docs/articles/view_demog_w_labels_20230217.png deleted file mode 100644 index 3af5776..0000000 Binary files a/docs/articles/view_demog_w_labels_20230217.png and /dev/null differ diff --git a/docs/authors.html b/docs/authors.html deleted file mode 100644 index 5db2745..0000000 --- a/docs/authors.html +++ /dev/null @@ -1,150 +0,0 @@ - -Authors and Citation β€’ tidyREDCap - - -
-
- - - -
-
-
- - - -
  • -

    Raymond Balise. Author, maintainer. -

    -
  • -
  • -

    Gabriel Odom. Author. -

    -
  • -
  • -

    Anna Calderon. Author. -

    -
  • -
  • -

    Layla Bouzoubaa. Author. -

    -
  • -
  • -

    Wayne DeFreitas. Author. -

    -
  • -
  • -

    Lauren Nahodyl. Contributor. -

    -
  • -
  • -

    Kyle Grealis. Author. -

    -
  • -
-
-
-

Citation

- Source: DESCRIPTION -
-
- - -

Balise R, Odom G, Calderon A, Bouzoubaa L, DeFreitas W, Grealis K (2023). -tidyREDCap: Helper Functions for Working with 'REDCap' Data. -R package version 1.1.1, https://raymondbalise.github.io/tidyREDCap/index.html. -

-
@Manual{,
-  title = {tidyREDCap: Helper Functions for Working with 'REDCap' Data},
-  author = {Raymond Balise and Gabriel Odom and Anna Calderon and Layla Bouzoubaa and Wayne DeFreitas and Kyle Grealis},
-  year = {2023},
-  note = {R package version 1.1.1},
-  url = {https://raymondbalise.github.io/tidyREDCap/index.html},
-}
- -
- -
- - - -
- - - - - - - - diff --git a/docs/bootstrap-toc.css b/docs/bootstrap-toc.css deleted file mode 100644 index 5a85941..0000000 --- a/docs/bootstrap-toc.css +++ /dev/null @@ -1,60 +0,0 @@ -/*! - * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) - * Copyright 2015 Aidan Feldman - * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ - -/* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ - -/* All levels of nav */ -nav[data-toggle='toc'] .nav > li > a { - display: block; - padding: 4px 20px; - font-size: 13px; - font-weight: 500; - color: #767676; -} -nav[data-toggle='toc'] .nav > li > a:hover, -nav[data-toggle='toc'] .nav > li > a:focus { - padding-left: 19px; - color: #563d7c; - text-decoration: none; - background-color: transparent; - border-left: 1px solid #563d7c; -} -nav[data-toggle='toc'] .nav > .active > a, -nav[data-toggle='toc'] .nav > .active:hover > a, -nav[data-toggle='toc'] .nav > .active:focus > a { - padding-left: 18px; - font-weight: bold; - color: #563d7c; - background-color: transparent; - border-left: 2px solid #563d7c; -} - -/* Nav: second level (shown on .active) */ -nav[data-toggle='toc'] .nav .nav { - display: none; /* Hide by default, but at >768px, show it */ - padding-bottom: 10px; -} -nav[data-toggle='toc'] .nav .nav > li > a { - padding-top: 1px; - padding-bottom: 1px; - padding-left: 30px; - font-size: 12px; - font-weight: normal; -} -nav[data-toggle='toc'] .nav .nav > li > a:hover, -nav[data-toggle='toc'] .nav .nav > li > a:focus { - padding-left: 29px; -} -nav[data-toggle='toc'] .nav .nav > .active > a, -nav[data-toggle='toc'] .nav .nav > .active:hover > a, -nav[data-toggle='toc'] .nav .nav > .active:focus > a { - padding-left: 28px; - font-weight: 500; -} - -/* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ -nav[data-toggle='toc'] .nav > .active > ul { - display: block; -} diff --git a/docs/bootstrap-toc.js b/docs/bootstrap-toc.js deleted file mode 100644 index 1cdd573..0000000 --- a/docs/bootstrap-toc.js +++ /dev/null @@ -1,159 +0,0 @@ -/*! - * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) - * Copyright 2015 Aidan Feldman - * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ -(function() { - 'use strict'; - - window.Toc = { - helpers: { - // return all matching elements in the set, or their descendants - findOrFilter: function($el, selector) { - // http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/ - // http://stackoverflow.com/a/12731439/358804 - var $descendants = $el.find(selector); - return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])'); - }, - - generateUniqueIdBase: function(el) { - var text = $(el).text(); - var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-'); - return anchor || el.tagName.toLowerCase(); - }, - - generateUniqueId: function(el) { - var anchorBase = this.generateUniqueIdBase(el); - for (var i = 0; ; i++) { - var anchor = anchorBase; - if (i > 0) { - // add suffix - anchor += '-' + i; - } - // check if ID already exists - if (!document.getElementById(anchor)) { - return anchor; - } - } - }, - - generateAnchor: function(el) { - if (el.id) { - return el.id; - } else { - var anchor = this.generateUniqueId(el); - el.id = anchor; - return anchor; - } - }, - - createNavList: function() { - return $(''); - }, - - createChildNavList: function($parent) { - var $childList = this.createNavList(); - $parent.append($childList); - return $childList; - }, - - generateNavEl: function(anchor, text) { - var $a = $(''); - $a.attr('href', '#' + anchor); - $a.text(text); - var $li = $('
  • '); - $li.append($a); - return $li; - }, - - generateNavItem: function(headingEl) { - var anchor = this.generateAnchor(headingEl); - var $heading = $(headingEl); - var text = $heading.data('toc-text') || $heading.text(); - return this.generateNavEl(anchor, text); - }, - - // Find the first heading level (`

    `, then `

    `, etc.) that has more than one element. Defaults to 1 (for `

    `). - getTopLevel: function($scope) { - for (var i = 1; i <= 6; i++) { - var $headings = this.findOrFilter($scope, 'h' + i); - if ($headings.length > 1) { - return i; - } - } - - return 1; - }, - - // returns the elements for the top level, and the next below it - getHeadings: function($scope, topLevel) { - var topSelector = 'h' + topLevel; - - var secondaryLevel = topLevel + 1; - var secondarySelector = 'h' + secondaryLevel; - - return this.findOrFilter($scope, topSelector + ',' + secondarySelector); - }, - - getNavLevel: function(el) { - return parseInt(el.tagName.charAt(1), 10); - }, - - populateNav: function($topContext, topLevel, $headings) { - var $context = $topContext; - var $prevNav; - - var helpers = this; - $headings.each(function(i, el) { - var $newNav = helpers.generateNavItem(el); - var navLevel = helpers.getNavLevel(el); - - // determine the proper $context - if (navLevel === topLevel) { - // use top level - $context = $topContext; - } else if ($prevNav && $context === $topContext) { - // create a new level of the tree and switch to it - $context = helpers.createChildNavList($prevNav); - } // else use the current $context - - $context.append($newNav); - - $prevNav = $newNav; - }); - }, - - parseOps: function(arg) { - var opts; - if (arg.jquery) { - opts = { - $nav: arg - }; - } else { - opts = arg; - } - opts.$scope = opts.$scope || $(document.body); - return opts; - } - }, - - // accepts a jQuery object, or an options object - init: function(opts) { - opts = this.helpers.parseOps(opts); - - // ensure that the data attribute is in place for styling - opts.$nav.attr('data-toggle', 'toc'); - - var $topContext = this.helpers.createChildNavList(opts.$nav); - var topLevel = this.helpers.getTopLevel(opts.$scope); - var $headings = this.helpers.getHeadings(opts.$scope, topLevel); - this.helpers.populateNav($topContext, topLevel, $headings); - } - }; - - $(function() { - $('nav[data-toggle="toc"]').each(function(i, el) { - var $nav = $(el); - Toc.init($nav); - }); - }); -})(); diff --git a/docs/docsearch.css b/docs/docsearch.css deleted file mode 100644 index e5f1fe1..0000000 --- a/docs/docsearch.css +++ /dev/null @@ -1,148 +0,0 @@ -/* Docsearch -------------------------------------------------------------- */ -/* - Source: https://github.com/algolia/docsearch/ - License: MIT -*/ - -.algolia-autocomplete { - display: block; - -webkit-box-flex: 1; - -ms-flex: 1; - flex: 1 -} - -.algolia-autocomplete .ds-dropdown-menu { - width: 100%; - min-width: none; - max-width: none; - padding: .75rem 0; - background-color: #fff; - background-clip: padding-box; - border: 1px solid rgba(0, 0, 0, .1); - box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .175); -} - -@media (min-width:768px) { - .algolia-autocomplete .ds-dropdown-menu { - width: 175% - } -} - -.algolia-autocomplete .ds-dropdown-menu::before { - display: none -} - -.algolia-autocomplete .ds-dropdown-menu [class^=ds-dataset-] { - padding: 0; - background-color: rgb(255,255,255); - border: 0; - max-height: 80vh; -} - -.algolia-autocomplete .ds-dropdown-menu .ds-suggestions { - margin-top: 0 -} - -.algolia-autocomplete .algolia-docsearch-suggestion { - padding: 0; - overflow: visible -} - -.algolia-autocomplete .algolia-docsearch-suggestion--category-header { - padding: .125rem 1rem; - margin-top: 0; - font-size: 1.3em; - font-weight: 500; - color: #00008B; - border-bottom: 0 -} - -.algolia-autocomplete .algolia-docsearch-suggestion--wrapper { - float: none; - padding-top: 0 -} - -.algolia-autocomplete .algolia-docsearch-suggestion--subcategory-column { - float: none; - width: auto; - padding: 0; - text-align: left -} - -.algolia-autocomplete .algolia-docsearch-suggestion--content { - float: none; - width: auto; - padding: 0 -} - -.algolia-autocomplete .algolia-docsearch-suggestion--content::before { - display: none -} - -.algolia-autocomplete .ds-suggestion:not(:first-child) .algolia-docsearch-suggestion--category-header { - padding-top: .75rem; - margin-top: .75rem; - border-top: 1px solid rgba(0, 0, 0, .1) -} - -.algolia-autocomplete .ds-suggestion .algolia-docsearch-suggestion--subcategory-column { - display: block; - padding: .1rem 1rem; - margin-bottom: 0.1; - font-size: 1.0em; - font-weight: 400 - /* display: none */ -} - -.algolia-autocomplete .algolia-docsearch-suggestion--title { - display: block; - padding: .25rem 1rem; - margin-bottom: 0; - font-size: 0.9em; - font-weight: 400 -} - -.algolia-autocomplete .algolia-docsearch-suggestion--text { - padding: 0 1rem .5rem; - margin-top: -.25rem; - font-size: 0.8em; - font-weight: 400; - line-height: 1.25 -} - -.algolia-autocomplete .algolia-docsearch-footer { - width: 110px; - height: 20px; - z-index: 3; - margin-top: 10.66667px; - float: right; - font-size: 0; - line-height: 0; -} - -.algolia-autocomplete .algolia-docsearch-footer--logo { - background-image: url("data:image/svg+xml;utf8,"); - background-repeat: no-repeat; - background-position: 50%; - background-size: 100%; - overflow: hidden; - text-indent: -9000px; - width: 100%; - height: 100%; - display: block; - transform: translate(-8px); -} - -.algolia-autocomplete .algolia-docsearch-suggestion--highlight { - color: #FF8C00; - background: rgba(232, 189, 54, 0.1) -} - - -.algolia-autocomplete .algolia-docsearch-suggestion--text .algolia-docsearch-suggestion--highlight { - box-shadow: inset 0 -2px 0 0 rgba(105, 105, 105, .5) -} - -.algolia-autocomplete .ds-suggestion.ds-cursor .algolia-docsearch-suggestion--content { - background-color: rgba(192, 192, 192, .15) -} diff --git a/docs/docsearch.js b/docs/docsearch.js deleted file mode 100644 index b35504c..0000000 --- a/docs/docsearch.js +++ /dev/null @@ -1,85 +0,0 @@ -$(function() { - - // register a handler to move the focus to the search bar - // upon pressing shift + "/" (i.e. "?") - $(document).on('keydown', function(e) { - if (e.shiftKey && e.keyCode == 191) { - e.preventDefault(); - $("#search-input").focus(); - } - }); - - $(document).ready(function() { - // do keyword highlighting - /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ - var mark = function() { - - var referrer = document.URL ; - var paramKey = "q" ; - - if (referrer.indexOf("?") !== -1) { - var qs = referrer.substr(referrer.indexOf('?') + 1); - var qs_noanchor = qs.split('#')[0]; - var qsa = qs_noanchor.split('&'); - var keyword = ""; - - for (var i = 0; i < qsa.length; i++) { - var currentParam = qsa[i].split('='); - - if (currentParam.length !== 2) { - continue; - } - - if (currentParam[0] == paramKey) { - keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); - } - } - - if (keyword !== "") { - $(".contents").unmark({ - done: function() { - $(".contents").mark(keyword); - } - }); - } - } - }; - - mark(); - }); -}); - -/* Search term highlighting ------------------------------*/ - -function matchedWords(hit) { - var words = []; - - var hierarchy = hit._highlightResult.hierarchy; - // loop to fetch from lvl0, lvl1, etc. - for (var idx in hierarchy) { - words = words.concat(hierarchy[idx].matchedWords); - } - - var content = hit._highlightResult.content; - if (content) { - words = words.concat(content.matchedWords); - } - - // return unique words - var words_uniq = [...new Set(words)]; - return words_uniq; -} - -function updateHitURL(hit) { - - var words = matchedWords(hit); - var url = ""; - - if (hit.anchor) { - url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; - } else { - url = hit.url + '?q=' + escape(words.join(" ")); - } - - return url; -} diff --git a/docs/favicon-16x16.png b/docs/favicon-16x16.png deleted file mode 100644 index 665a148..0000000 Binary files a/docs/favicon-16x16.png and /dev/null differ diff --git a/docs/favicon-32x32.png b/docs/favicon-32x32.png deleted file mode 100644 index bbf4579..0000000 Binary files a/docs/favicon-32x32.png and /dev/null differ diff --git a/docs/favicon.ico b/docs/favicon.ico deleted file mode 100644 index 35d58e9..0000000 Binary files a/docs/favicon.ico and /dev/null differ diff --git a/docs/index.html b/docs/index.html deleted file mode 100644 index 5115607..0000000 --- a/docs/index.html +++ /dev/null @@ -1,293 +0,0 @@ - - - - - - - -Helper Functions for Working with REDCap Data β€’ tidyREDCap - - - - - - - - - - - - - - - - - - - -
    -
    - - - - -
    -
    - -

    CRAN status Lifecycle: maturing CRAN downloads

    -

    -
    - -

    tidyREDCap is an R package with functions for processing REDCap data.

    -

    β€˜REDCap’ (Research Electronic Data CAPture; https://projectredcap.org) is a web-enabled application for building and managing surveys and databases developed at Vanderbilt University.

    -
    -

    What tidyREDCap Functions Can Do for You? -

    -
    -

    Load All Data from REDCap into R with One Line of Code -

    -
      -
    • πŸ’₯ NEW in Version 1.1 πŸ’₯ import_instruments() includes the repeat number for repeated instruments/forms/questionnaires.

    • -
    • import_instruments() will use an API call to load every instrument/questionnaire into its own R dataset. If the REDCap project is longitudinal or has repeated instruments, the function will remove blank records.

    • -
    -
    -
    -

    Show the Field Labels Inside RStudio -

    -
      -
    • After loading data into R using RStudio with the import_instruments() function, you can see both the variable name and the text that appears to users of REDCap. All you need to do is click on the dataset’s name in the Environment tab or use the View() function. The column headings will include both the variable name and the Field Label from REDCap.

    • -
    • πŸ’₯ NEW in Version 1.1 πŸ’₯ Functions coming from packages outside of tidyREDCap may not understand what to do with labeled variables. So, tidyREDCap includes a new drop_labels() function that will allow you to strip the labels before using functions that want unlabeled data.

    • -
    -
    -
    -

    Working with Choose One Questions -

    - -
    -
    -

    Working with Choose All that Apply Questions -

    -

    REDCap exports the responses to a choose all that apply question into many similarly named questions. tidyREDCap helps summarize the responses with two functions:

    - -
    -
    -

    Working with Repeated Measures -

    -

    Projects that have repeated assessments with different questionnaires/instruments export with holes in the CSV. tidyREDCap will parse the export and create tables for any of the questionnaires/instruments:

    - -
    -
    - -
    -

    Where Can I Find tidyREDCap? -

    -
    -

    Offical Release -

    -

    You can get the latest official release of tidyREDCap from CRAN.

    -
    install.packages("tidyREDCap")
    -
    -
    -

    Development Release -

    -

    Run these two lines of code to install tidyREDCap from GitHub (this requires RTools for Windows or Xcode for Mac to be installed on your computer):

    -
    if (!requireNamespace("devtools")) install.packages("devtools")
    -devtools::install_github("RaymondBalise/tidyREDCap")
    -
    -
    -

    What is new on the development release? -

    -
      -
    • πŸ’₯ NEW in Version 1.1.0.9000 πŸ’₯ adds make_yes_no() function to convert β€œchecked” or β€œyes”-like answers to β€œYes” and other answers to β€œNo or Unknown”.
    • -
    • πŸ’₯ NEW in Version 1.1.0.9000 πŸ’₯ adds make_yes_no_unknown() function to convert β€œchecked” or β€œyes”-like answers to β€œYesβ€β€œ, unchecked or”no”-like answers to β€œNo” and other answers to β€œUnknown”.
    • -
    -
    -
    -
    -

    What if I Find a Problem? -

    -

    We are currently in active development of tidyREDCap. If one of our functions does not work the way that you expect, or if one of our functions is broken, please submit an issue ticket (using a reproducible example) to our issues page. If you have a cool idea for our next new function, also submit an issue ticket. If you are an R developer and want so contribute to this package, please submit an issue ticket or a pull request.

    -
    -
    -

    Who Are Our Supporters? -

    -

    The development of this package was supported by:

    -
      -
    • Healing Communities Study: Developing and Testing and Integrated Approach to Address the Opioid Crisis-New York State. -
        -
      • National Institute on Drug Abuse, 1 UM1 DA049415
      • -
      -
    • -
    • CTN-0094 Individual Level Predictive Modeling of Opioid Use Disorder Treatment Outcome. -
        -
      • Florida Node Alliance Of The Drug Abuse Clinical Trials Network NIDA UG1 DA013720
      • -
      -
    • -
    • University of Miami Center for HIV and Researching Mental Health (CHARM) -
        -
      • NIH 1P30MH116867-01A1
      • -
      -
    • -
    • University of Miami, Sylvester Comprehensive Cancer Center
    • -
    • Florida International University, Stempel College of Public Health
    • -
    -
    -
    - -
    - - -
    - - -
    - -
    -

    -

    Site built with pkgdown 2.0.7.

    -
    - -
    -
    - - - - - - - - diff --git a/docs/link.svg b/docs/link.svg deleted file mode 100644 index 88ad827..0000000 --- a/docs/link.svg +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - diff --git a/docs/logo.png b/docs/logo.png deleted file mode 100644 index 9f87fcf..0000000 Binary files a/docs/logo.png and /dev/null differ diff --git a/docs/news/index.html b/docs/news/index.html deleted file mode 100644 index 419c613..0000000 --- a/docs/news/index.html +++ /dev/null @@ -1,246 +0,0 @@ - -Changelog β€’ tidyREDCap - - -
    -
    - - - -
    -
    - - -
    - -
    -

    New features

    -
    • Add make_yes_no() function to convert β€œchecked” or β€œyes”-like answers to β€œYes” and other answers to β€œNo or Unknown”.
    • -
    • Add make_yes_no_unknown() function to convert β€œchecked” or β€œyes”-like answers to β€œYesβ€β€œ, unchecked or”no”-like answers to β€œNo” and other answers to β€œUnknown”.
    • -
    -
    -

    Fixes/Changes

    -
    • -make_choose_all_table() now works with api or manual/point-and-click exports. ## Added S3 methods so dplyr (and friends) can work with labelled objects
    • -
    -
    -
    - -
    -

    New features

    -
    • Add drop_labels() function for datasets. Used to deal with packages/functions that don’t want labeled variables (i.e.Β dplyr::pivot_longer() and skimr::skim() -
    • -
    • Added options (record_id = and first_record_id = for custom record_id fields in import_instruments() -
    • -
    • Added repeat instance numbers for repeated instruments in import_instruments() -
    • -
    -
    -

    Fixes/Changes

    -
    • Documentation fixes -
      • Suppress warning caused by dplyr 1.1
      • -
      • fix wrong function in api vignette
      • -
    • -
    -
    -

    Minor improvements and fixes

    -
    • Add unit test on import_instruments() function call.
    • -
    -
    -
    - -
    -

    Fixes/Changes

    -
    • Fixed bug that caused labels to be missing if they contained parentheses
    • -
    -
    -
    - -
    -

    New features

    -
    • Add drop label function
    • -
    -
    -

    Fixes/Changes

    -
    • Fix message display bug while import_instruments() runs
    • -
    • Fix bug with import_instruments() loading repeated instruments (the first instrument in a project was badly messed up)
    • -
    • Row names no longer reflect the row number of the exported data
    • -
    • Remove labels from a few automatically created REDCap variables (β€œrecord_id”, β€œredcap_event_name”, β€œredcap_repeat_instrument”, β€œredcap_repeat_instance”)
    • -
    -
    -
    - -
    -

    New features

    -
    • Added support for REDCapR API -
      • -import_instruments() function imports all instruments with a single command
      • -
      • Added targeted status messaging during the import
      • -
    • -
    -
    -

    Minor improvements and fixes

    -
    -
    -
    - -
    • Add {REDCapR} support
    • -
    • Added import_instruments() function to import all instruments; currently uses the REDCapR package as the API
    • -
    -
    - -
    -
    - -
    -
    - -
    -
    - -
    • Fix bug with β€œβ€ character stings with make_instrument()
    • -
    -
    - -
    • Cleaned up vignettes, docs
    • -
    -
    - -
    • Cleaned up vignettes, docs
    • -
    -
    - -
    -
    - -
    • Cleaned up vignettes
    • -
    -
    - -
    -
    - -
    -
    - -
    • Fixed title capitalization.
    • -
    • Added reference to REDCap website.
    • -
    • Updated the release year in the license.
    • -
    • Updated hyperlinks to vignettes and example instrument description.
    • -
    • Added references to financial support in the ReadMe.
    • -
    -
    - -
    • Added check on number of arguments
    • -
    -
    - -
    • Added a NEWS.md file to track changes to the package.
    • -
    -
    - - - -
    - - -
    - -
    -

    Site built with pkgdown 2.0.7.

    -
    - -
    - - - - - - - - diff --git a/docs/pkgdown.css b/docs/pkgdown.css deleted file mode 100644 index 80ea5b8..0000000 --- a/docs/pkgdown.css +++ /dev/null @@ -1,384 +0,0 @@ -/* Sticky footer */ - -/** - * Basic idea: https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/ - * Details: https://github.com/philipwalton/solved-by-flexbox/blob/master/assets/css/components/site.css - * - * .Site -> body > .container - * .Site-content -> body > .container .row - * .footer -> footer - * - * Key idea seems to be to ensure that .container and __all its parents__ - * have height set to 100% - * - */ - -html, body { - height: 100%; -} - -body { - position: relative; -} - -body > .container { - display: flex; - height: 100%; - flex-direction: column; -} - -body > .container .row { - flex: 1 0 auto; -} - -footer { - margin-top: 45px; - padding: 35px 0 36px; - border-top: 1px solid #e5e5e5; - color: #666; - display: flex; - flex-shrink: 0; -} -footer p { - margin-bottom: 0; -} -footer div { - flex: 1; -} -footer .pkgdown { - text-align: right; -} -footer p { - margin-bottom: 0; -} - -img.icon { - float: right; -} - -/* Ensure in-page images don't run outside their container */ -.contents img { - max-width: 100%; - height: auto; -} - -/* Fix bug in bootstrap (only seen in firefox) */ -summary { - display: list-item; -} - -/* Typographic tweaking ---------------------------------*/ - -.contents .page-header { - margin-top: calc(-60px + 1em); -} - -dd { - margin-left: 3em; -} - -/* Section anchors ---------------------------------*/ - -a.anchor { - display: none; - margin-left: 5px; - width: 20px; - height: 20px; - - background-image: url(./link.svg); - background-repeat: no-repeat; - background-size: 20px 20px; - background-position: center center; -} - -h1:hover .anchor, -h2:hover .anchor, -h3:hover .anchor, -h4:hover .anchor, -h5:hover .anchor, -h6:hover .anchor { - display: inline-block; -} - -/* Fixes for fixed navbar --------------------------*/ - -.contents h1, .contents h2, .contents h3, .contents h4 { - padding-top: 60px; - margin-top: -40px; -} - -/* Navbar submenu --------------------------*/ - -.dropdown-submenu { - position: relative; -} - -.dropdown-submenu>.dropdown-menu { - top: 0; - left: 100%; - margin-top: -6px; - margin-left: -1px; - border-radius: 0 6px 6px 6px; -} - -.dropdown-submenu:hover>.dropdown-menu { - display: block; -} - -.dropdown-submenu>a:after { - display: block; - content: " "; - float: right; - width: 0; - height: 0; - border-color: transparent; - border-style: solid; - border-width: 5px 0 5px 5px; - border-left-color: #cccccc; - margin-top: 5px; - margin-right: -10px; -} - -.dropdown-submenu:hover>a:after { - border-left-color: #ffffff; -} - -.dropdown-submenu.pull-left { - float: none; -} - -.dropdown-submenu.pull-left>.dropdown-menu { - left: -100%; - margin-left: 10px; - border-radius: 6px 0 6px 6px; -} - -/* Sidebar --------------------------*/ - -#pkgdown-sidebar { - margin-top: 30px; - position: -webkit-sticky; - position: sticky; - top: 70px; -} - -#pkgdown-sidebar h2 { - font-size: 1.5em; - margin-top: 1em; -} - -#pkgdown-sidebar h2:first-child { - margin-top: 0; -} - -#pkgdown-sidebar .list-unstyled li { - margin-bottom: 0.5em; -} - -/* bootstrap-toc tweaks ------------------------------------------------------*/ - -/* All levels of nav */ - -nav[data-toggle='toc'] .nav > li > a { - padding: 4px 20px 4px 6px; - font-size: 1.5rem; - font-weight: 400; - color: inherit; -} - -nav[data-toggle='toc'] .nav > li > a:hover, -nav[data-toggle='toc'] .nav > li > a:focus { - padding-left: 5px; - color: inherit; - border-left: 1px solid #878787; -} - -nav[data-toggle='toc'] .nav > .active > a, -nav[data-toggle='toc'] .nav > .active:hover > a, -nav[data-toggle='toc'] .nav > .active:focus > a { - padding-left: 5px; - font-size: 1.5rem; - font-weight: 400; - color: inherit; - border-left: 2px solid #878787; -} - -/* Nav: second level (shown on .active) */ - -nav[data-toggle='toc'] .nav .nav { - display: none; /* Hide by default, but at >768px, show it */ - padding-bottom: 10px; -} - -nav[data-toggle='toc'] .nav .nav > li > a { - padding-left: 16px; - font-size: 1.35rem; -} - -nav[data-toggle='toc'] .nav .nav > li > a:hover, -nav[data-toggle='toc'] .nav .nav > li > a:focus { - padding-left: 15px; -} - -nav[data-toggle='toc'] .nav .nav > .active > a, -nav[data-toggle='toc'] .nav .nav > .active:hover > a, -nav[data-toggle='toc'] .nav .nav > .active:focus > a { - padding-left: 15px; - font-weight: 500; - font-size: 1.35rem; -} - -/* orcid ------------------------------------------------------------------- */ - -.orcid { - font-size: 16px; - color: #A6CE39; - /* margins are required by official ORCID trademark and display guidelines */ - margin-left:4px; - margin-right:4px; - vertical-align: middle; -} - -/* Reference index & topics ----------------------------------------------- */ - -.ref-index th {font-weight: normal;} - -.ref-index td {vertical-align: top; min-width: 100px} -.ref-index .icon {width: 40px;} -.ref-index .alias {width: 40%;} -.ref-index-icons .alias {width: calc(40% - 40px);} -.ref-index .title {width: 60%;} - -.ref-arguments th {text-align: right; padding-right: 10px;} -.ref-arguments th, .ref-arguments td {vertical-align: top; min-width: 100px} -.ref-arguments .name {width: 20%;} -.ref-arguments .desc {width: 80%;} - -/* Nice scrolling for wide elements --------------------------------------- */ - -table { - display: block; - overflow: auto; -} - -/* Syntax highlighting ---------------------------------------------------- */ - -pre, code, pre code { - background-color: #f8f8f8; - color: #333; -} -pre, pre code { - white-space: pre-wrap; - word-break: break-all; - overflow-wrap: break-word; -} - -pre { - border: 1px solid #eee; -} - -pre .img, pre .r-plt { - margin: 5px 0; -} - -pre .img img, pre .r-plt img { - background-color: #fff; -} - -code a, pre a { - color: #375f84; -} - -a.sourceLine:hover { - text-decoration: none; -} - -.fl {color: #1514b5;} -.fu {color: #000000;} /* function */ -.ch,.st {color: #036a07;} /* string */ -.kw {color: #264D66;} /* keyword */ -.co {color: #888888;} /* comment */ - -.error {font-weight: bolder;} -.warning {font-weight: bolder;} - -/* Clipboard --------------------------*/ - -.hasCopyButton { - position: relative; -} - -.btn-copy-ex { - position: absolute; - right: 0; - top: 0; - visibility: hidden; -} - -.hasCopyButton:hover button.btn-copy-ex { - visibility: visible; -} - -/* headroom.js ------------------------ */ - -.headroom { - will-change: transform; - transition: transform 200ms linear; -} -.headroom--pinned { - transform: translateY(0%); -} -.headroom--unpinned { - transform: translateY(-100%); -} - -/* mark.js ----------------------------*/ - -mark { - background-color: rgba(255, 255, 51, 0.5); - border-bottom: 2px solid rgba(255, 153, 51, 0.3); - padding: 1px; -} - -/* vertical spacing after htmlwidgets */ -.html-widget { - margin-bottom: 10px; -} - -/* fontawesome ------------------------ */ - -.fab { - font-family: "Font Awesome 5 Brands" !important; -} - -/* don't display links in code chunks when printing */ -/* source: https://stackoverflow.com/a/10781533 */ -@media print { - code a:link:after, code a:visited:after { - content: ""; - } -} - -/* Section anchors --------------------------------- - Added in pandoc 2.11: https://github.com/jgm/pandoc-templates/commit/9904bf71 -*/ - -div.csl-bib-body { } -div.csl-entry { - clear: both; -} -.hanging-indent div.csl-entry { - margin-left:2em; - text-indent:-2em; -} -div.csl-left-margin { - min-width:2em; - float:left; -} -div.csl-right-inline { - margin-left:2em; - padding-left:1em; -} -div.csl-indent { - margin-left: 2em; -} diff --git a/docs/pkgdown.js b/docs/pkgdown.js deleted file mode 100644 index 6f0eee4..0000000 --- a/docs/pkgdown.js +++ /dev/null @@ -1,108 +0,0 @@ -/* http://gregfranko.com/blog/jquery-best-practices/ */ -(function($) { - $(function() { - - $('.navbar-fixed-top').headroom(); - - $('body').css('padding-top', $('.navbar').height() + 10); - $(window).resize(function(){ - $('body').css('padding-top', $('.navbar').height() + 10); - }); - - $('[data-toggle="tooltip"]').tooltip(); - - var cur_path = paths(location.pathname); - var links = $("#navbar ul li a"); - var max_length = -1; - var pos = -1; - for (var i = 0; i < links.length; i++) { - if (links[i].getAttribute("href") === "#") - continue; - // Ignore external links - if (links[i].host !== location.host) - continue; - - var nav_path = paths(links[i].pathname); - - var length = prefix_length(nav_path, cur_path); - if (length > max_length) { - max_length = length; - pos = i; - } - } - - // Add class to parent
  • , and enclosing
  • if in dropdown - if (pos >= 0) { - var menu_anchor = $(links[pos]); - menu_anchor.parent().addClass("active"); - menu_anchor.closest("li.dropdown").addClass("active"); - } - }); - - function paths(pathname) { - var pieces = pathname.split("/"); - pieces.shift(); // always starts with / - - var end = pieces[pieces.length - 1]; - if (end === "index.html" || end === "") - pieces.pop(); - return(pieces); - } - - // Returns -1 if not found - function prefix_length(needle, haystack) { - if (needle.length > haystack.length) - return(-1); - - // Special case for length-0 haystack, since for loop won't run - if (haystack.length === 0) { - return(needle.length === 0 ? 0 : -1); - } - - for (var i = 0; i < haystack.length; i++) { - if (needle[i] != haystack[i]) - return(i); - } - - return(haystack.length); - } - - /* Clipboard --------------------------*/ - - function changeTooltipMessage(element, msg) { - var tooltipOriginalTitle=element.getAttribute('data-original-title'); - element.setAttribute('data-original-title', msg); - $(element).tooltip('show'); - element.setAttribute('data-original-title', tooltipOriginalTitle); - } - - if(ClipboardJS.isSupported()) { - $(document).ready(function() { - var copyButton = ""; - - $("div.sourceCode").addClass("hasCopyButton"); - - // Insert copy buttons: - $(copyButton).prependTo(".hasCopyButton"); - - // Initialize tooltips: - $('.btn-copy-ex').tooltip({container: 'body'}); - - // Initialize clipboard: - var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { - text: function(trigger) { - return trigger.parentNode.textContent.replace(/\n#>[^\n]*/g, ""); - } - }); - - clipboardBtnCopies.on('success', function(e) { - changeTooltipMessage(e.trigger, 'Copied!'); - e.clearSelection(); - }); - - clipboardBtnCopies.on('error', function() { - changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); - }); - }); - } -})(window.jQuery || window.$) diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml deleted file mode 100644 index 7b7a5ef..0000000 --- a/docs/pkgdown.yml +++ /dev/null @@ -1,13 +0,0 @@ -pandoc: 2.19.2 -pkgdown: 2.0.7 -pkgdown_sha: ~ -articles: - dropLabels: dropLabels.html - import_instruments: import_instruments.html - makeBinaryWord: makeBinaryWord.html - makeChooseAllTable: makeChooseAllTable.html - makeChooseOneTable: makeChooseOneTable.html - makeInstrument: makeInstrument.html - useAPI: useAPI.html -last_built: 2023-05-29T16:22Z - diff --git a/docs/reference/.DS_Store b/docs/reference/.DS_Store deleted file mode 100644 index 82c0810..0000000 Binary files a/docs/reference/.DS_Store and /dev/null differ diff --git a/docs/reference/Rplot001.png b/docs/reference/Rplot001.png deleted file mode 100644 index 17a3580..0000000 Binary files a/docs/reference/Rplot001.png and /dev/null differ diff --git a/docs/reference/dropTags.html b/docs/reference/dropTags.html deleted file mode 100644 index 506701d..0000000 --- a/docs/reference/dropTags.html +++ /dev/null @@ -1,111 +0,0 @@ - -dropTags β€” dropTags β€’ tidyREDCap - - -
    -
    - - - -
    -
    - - -
    -

    Cuts html tags from a variable. Used to clean labels

    -
    - -
    -
    dropTags(x)
    -
    - -
    -

    Arguments

    -
    x
    -

    a string

    -
    -
    -

    Value

    -

    a string

    -
    - -
    - -
    - - -
    - -
    -

    Site built with pkgdown 2.0.1.

    -
    - -
    - - - - - - - - diff --git a/docs/reference/drop_label.html b/docs/reference/drop_label.html deleted file mode 100644 index 27ce13b..0000000 --- a/docs/reference/drop_label.html +++ /dev/null @@ -1,131 +0,0 @@ - -Drop the label from a variable β€” drop_label β€’ tidyREDCap - - -
    -
    - - - -
    -
    - - -
    -

    There is a reported issues with joins on data (without a reprex) -that seem to be caused by the labels. As a possible solution this can be -used to drop labels.

    -
    - -
    -
    drop_label(df, x)
    -
    - -
    -

    Arguments

    -
    df
    -

    the name of the data frame

    - - -
    x
    -

    the quoted name of the variable

    - -
    -
    -

    Value

    - - -

    df

    -
    - -
    - -
    - - -
    - -
    -

    Site built with pkgdown 2.0.7.

    -
    - -
    - - - - - - - - diff --git a/docs/reference/drop_labels.html b/docs/reference/drop_labels.html deleted file mode 100644 index 5ec6fd5..0000000 --- a/docs/reference/drop_labels.html +++ /dev/null @@ -1,134 +0,0 @@ - -Drop all the labels from a variable β€” drop_labels β€’ tidyREDCap - - -
    -
    - - - -
    -
    - - -
    -

    There is an issue with the function we are using to add column -labels. If you run into problems processing the labels.

    -
    - -
    -
    drop_labels(df)
    -
    - -
    -

    Arguments

    -
    df
    -

    The data frame with column labels that you want to drop

    - -
    -
    -

    Value

    - - -

    df without column labels

    -
    - -
    -

    Examples

    -
    if (FALSE) {
    -demographics |>
    -  drop_labels() |>
    -  skimr::skim()
    -}
    -
    -
    -
    - -
    - - -
    - -
    -

    Site built with pkgdown 2.0.7.

    -
    - -
    - - - - - - - - diff --git a/docs/reference/figures/logo.png b/docs/reference/figures/logo.png deleted file mode 100644 index 9f87fcf..0000000 Binary files a/docs/reference/figures/logo.png and /dev/null differ diff --git a/docs/reference/getLabel2.html b/docs/reference/getLabel2.html deleted file mode 100644 index 21bc862..0000000 --- a/docs/reference/getLabel2.html +++ /dev/null @@ -1,114 +0,0 @@ - -Get a variable's label from a data frame and variable β€” getLabel2 β€’ tidyREDCap - - -
    -
    - - - -
    -
    - - -
    -

    Get a variable's label from a data frame and variable

    -
    - -
    -
    getLabel2(data, aVariable)
    -
    - -
    -

    Arguments

    -
    data
    -

    The name of the data set

    -
    aVariable
    -

    The name of the variable

    -
    -
    -

    Value

    -

    A variable's response label without the repeated text from of a -choose all that apply question

    -
    - -
    - -
    - - -
    - -
    -

    Site built with pkgdown 2.0.1.

    -
    - -
    - - - - - - - - diff --git a/docs/reference/import_instruments.html b/docs/reference/import_instruments.html deleted file mode 100644 index f6c42b4..0000000 --- a/docs/reference/import_instruments.html +++ /dev/null @@ -1,170 +0,0 @@ - -Import all instruments into individual R tables β€” import_instruments β€’ tidyREDCap - - -
    -
    - - - -
    -
    - - -
    -

    This function takes the url and key for a REDCap -project and returns a table for each instrument/form in the project.

    -
    - -
    -
    import_instruments(
    -  url,
    -  token,
    -  drop_blank = TRUE,
    -  record_id = "record_id",
    -  first_record_id = 1,
    -  envir = .GlobalEnv
    -)
    -
    - -
    -

    Arguments

    -
    url
    -

    The API URL for your the instance of REDCap

    - - -
    token
    -

    The API security token

    - - -
    drop_blank
    -

    Drop records that have no data. TRUE by default.

    - - -
    record_id
    -

    Name of record_id variable (if it was changed in REDCap).

    - - -
    first_record_id
    -

    A value of the custom record_id variable (if -changed in REDCap). To improve the speed of the import, tidyREDCap pulls -in a single record twice. By default if uses the first record. If you -have a custom record_id variable and if its the first record identifier -is not 1, specify a record identifier value here. For example if you -are using dude_id instead of record_id and dude_id has a value of -"first dude" for one of its records this argument would be -first_record_id = "first dude".

    - - -
    envir
    -

    The name of the environment where the tables should be saved.

    - -
    -
    -

    Value

    - - -

    one data.frame for each instrument/form in a REDCap project. By -default the datasets are saved into the global environment.

    -
    - -
    -

    Examples

    -
    if (FALSE) {
    -import_instruments(
    -  "https://redcap.miami.edu/api/",
    -  Sys.getenv("test_API_key")
    -)
    -}
    -
    -
    -
    - -
    - - -
    - -
    -

    Site built with pkgdown 2.0.7.

    -
    - -
    - - - - - - - - diff --git a/docs/reference/index.html b/docs/reference/index.html deleted file mode 100644 index 15d1d04..0000000 --- a/docs/reference/index.html +++ /dev/null @@ -1,145 +0,0 @@ - -Function reference β€’ tidyREDCap - - -
    -
    - - - -
    -
    - - - - - - - - - - - - - - - - - - - - - - - -
    -

    All functions

    -

    -
    -

    drop_label()

    -

    Drop the label from a variable

    -

    drop_labels()

    -

    Drop all the labels from a variable

    -

    import_instruments()

    -

    Import all instruments into individual R tables

    -

    make_binary_word()

    -

    Convert a "choose all that apply" Question Into a Binary Word

    -

    make_choose_all_table()

    -

    Count The Responses to a Choose All That Apply Question

    -

    make_choose_one_table()

    -

    Make a frequency table for a categorical variable

    -

    make_instrument()

    -

    Extract an Instrument from an REDCap Export

    -

    make_instrument_auto()

    -

    Extract an Instrument from an REDCap Export without specifying Variables

    -

    make_yes_no()

    -

    make_yes_no

    -

    make_yes_no_unknown()

    -

    make_yes_no_unknown

    - - -
    - - -
    - -
    -

    Site built with pkgdown 2.0.7.

    -
    - -
    - - - - - - - - diff --git a/docs/reference/make_binary_word.html b/docs/reference/make_binary_word.html deleted file mode 100644 index 4469af6..0000000 --- a/docs/reference/make_binary_word.html +++ /dev/null @@ -1,163 +0,0 @@ - -Convert a "choose all that apply" Question Into a Binary Word β€” make_binary_word β€’ tidyREDCap - - -
    -
    - - - -
    -
    - - -
    -

    This function takes a data frame holding binary variables with -values corresponding to a dummy-coded "choose all that apply" question. -It can be used for any binary word problem.

    -
    - -
    -
    make_binary_word(df, yes_value = "Checked", the_labels = letters)
    -
    - -
    -

    Arguments

    -
    df
    -

    A data frame with the variables corresponding to binary indicators -(the dummy coded variables) for a "choose all that apply" question.

    - - -
    yes_value
    -

    A character string that corresponds to choosing "yes" -in the binary variables of df. Defaults to the REDCap "Checked" option.

    - - -
    the_labels
    -

    A character vector of single letters holding the letters -used to make the binary word. See the article/vignette called "Make -Binary Word" for an example: -https://raymondbalise.github.io/tidyREDCap/articles/makeBinaryWord.html.

    - -
    -
    -

    Value

    - - -

    A character vector with length equal to the rows of df, including -one letter or underscore for each column of df. For instance, if df

    - - -

    has one column for each of the eight options of the Nacho Craving Index -example instrument (https://libguides.du.edu/c.php?g=948419&p=6839916), -with a row containing the values "Chips" (checked), "Yellow cheese" -(unchecked), "Orange cheese" (checked), "White cheese" (checked), "Meat" -(checked), "Beans" (unchecked), "Tomatoes" (unchecked) and "Peppers" -(checked), then the character string corresponding to that row will be -"a_cde__h". The underscores represent that the options for "Yellow -cheese", "Beans", and "Tomatoes" were left unchecked.

    -
    - -
    -

    Examples

    -
    test_df <- tibble::tibble(
    -  q1 = c("Unchecked", "Checked"),
    -  q2 = c("Unchecked", "Unchecked"),
    -  q3 = c("Checked", "Checked"),
    -  q4 = c("Checked", "Unchecked")
    -)
    -make_binary_word(test_df)
    -#> [1] "__cd" "a_c_"
    -
    -
    -
    - -
    - - -
    - -
    -

    Site built with pkgdown 2.0.7.

    -
    - -
    - - - - - - - - diff --git a/docs/reference/make_choose_all_table.html b/docs/reference/make_choose_all_table.html deleted file mode 100644 index 7bbcb1a..0000000 --- a/docs/reference/make_choose_all_table.html +++ /dev/null @@ -1,135 +0,0 @@ - -Count The Responses to a Choose All That Apply Question β€” make_choose_all_table β€’ tidyREDCap - - -
    -
    - - - -
    -
    - - -
    -

    This will tally the number of responses on a choose all that -apply question. This function extracts the option name from the variable -labels. So the data set needs to be labeled. See -the Make a 'Choose All' Table vignette -for help.

    -
    - -
    -
    make_choose_all_table(df, variable)
    -
    - -
    -

    Arguments

    -
    df
    -

    The name of the data set (it needs labels)

    - - -
    variable
    -

    The name of the REDCap variable

    - -
    -
    -

    Value

    - - -

    A variable's response label without the choose all the question

    -
    - -
    - -
    - - -
    - -
    -

    Site built with pkgdown 2.0.7.

    -
    - -
    - - - - - - - - diff --git a/docs/reference/make_choose_one_table.html b/docs/reference/make_choose_one_table.html deleted file mode 100644 index 8e811fb..0000000 --- a/docs/reference/make_choose_one_table.html +++ /dev/null @@ -1,141 +0,0 @@ - -Make a frequency table for a categorical variable β€” make_choose_one_table β€’ tidyREDCap - - -
    -
    - - - -
    -
    - - -
    -

    Pass this function either 1) a labeled factor or 2) -a data frame and also -a factor in the frame, and it will return a janitor-style table. -Use subset = TRUE if you are making a report on a variable that is part of -a choose all that apply question.

    -
    - -
    -
    make_choose_one_table(arg1, arg2, subset = FALSE)
    -
    - -
    -

    Arguments

    -
    arg1
    -

    data frame that has a factor or a factor name

    - - -
    arg2
    -

    if arg1 is a data frame, this is a factor name

    - - -
    subset
    -

    can be equal to TRUE/FALSE. This option removes extra variable -name text from the label. This option is useful for choose all that -apply questions.

    - -
    -
    -

    Value

    - - -

    a table

    -
    - -
    - -
    - - -
    - -
    -

    Site built with pkgdown 2.0.7.

    -
    - -
    - - - - - - - - diff --git a/docs/reference/make_instrument.html b/docs/reference/make_instrument.html deleted file mode 100644 index ea6c09c..0000000 --- a/docs/reference/make_instrument.html +++ /dev/null @@ -1,147 +0,0 @@ - -Extract an Instrument from an REDCap Export β€” make_instrument β€’ tidyREDCap - - -
    -
    - - - -
    -
    - - -
    -

    This function takes a data frame and the names of the first and -last variables in an instrumnt and returns a data frame with the instrument.

    -
    - -
    -
    make_instrument(
    -  df,
    -  first_var,
    -  last_var,
    -  drop_which_when = FALSE,
    -  record_id = "record_id"
    -)
    -
    - -
    -

    Arguments

    -
    df
    -

    A data frame with the instrument

    - - -
    first_var
    -

    The name of the first variable in an instrument

    - - -
    last_var
    -

    The name of the last variable in an instrument

    - - -
    drop_which_when
    -

    Drop the record_id and redcap_event_name variables

    - - -
    record_id
    -

    Name of record_id variable (if it was changed in REDCap)

    - -
    -
    -

    Value

    - - -

    A data frame that has an instrument (with at least one not NA value)

    -
    - -
    - -
    - - -
    - -
    -

    Site built with pkgdown 2.0.7.

    -
    - -
    - - - - - - - - diff --git a/docs/reference/make_instrument_auto.html b/docs/reference/make_instrument_auto.html deleted file mode 100644 index 2c93d8c..0000000 --- a/docs/reference/make_instrument_auto.html +++ /dev/null @@ -1,133 +0,0 @@ - -Extract an Instrument from an REDCap Export without specifying Variables β€” make_instrument_auto β€’ tidyREDCap - - -
    -
    - - - -
    -
    - - -
    -

    This function takes a data frame holding REDCap data, -checks if it is a longitudinal study, and returns records that have values.

    -
    - -
    -
    make_instrument_auto(df, drop_which_when = FALSE, record_id = "record_id")
    -
    - -
    -

    Arguments

    -
    df
    -

    A data frame with the instrument

    - - -
    drop_which_when
    -

    Drop the record_id and redcap_event_name variables

    - - -
    record_id
    -

    Name of record_id variable (if it was changed in REDCap)

    - -
    -
    -

    Value

    - - -

    A data frame that has an instrument (with at least one not NA value).

    -
    - -
    - -
    - - -
    - -
    -

    Site built with pkgdown 2.0.7.

    -
    - -
    - - - - - - - - diff --git a/docs/reference/make_yes_no.html b/docs/reference/make_yes_no.html deleted file mode 100644 index aba8820..0000000 --- a/docs/reference/make_yes_no.html +++ /dev/null @@ -1,141 +0,0 @@ - -make_yes_no β€” make_yes_no β€’ tidyREDCap - - -
    -
    - - - -
    -
    - - -
    -

    Convert a "Yes-No", "True-False" or "Checkboxes (Multiple -Answers)" question in REDCap to a factor holding "Yes" or -"No or Unknown". Technically "yes" or "checked" (ignoring case), 1 or -TRUE responses are converted to "Yes" and all other values to -"No or Unknown". Also see make_yes_no_unknown().

    -
    - -
    -
    make_yes_no(x)
    -
    - -
    -

    Arguments

    -
    x
    -

    x variable to be converted to hold "Yes" or "No or Unknown"

    - -
    -
    -

    Value

    - - -

    a factor with "Yes" or "No or Unknown"

    -
    - -
    -

    Examples

    -
    make_yes_no(c(0, 1, NA))
    -#> [1] No or Unknown Yes           No or Unknown
    -#> Levels: No or Unknown Yes
    -make_yes_no(c("unchecked", "Checked", NA))
    -#> [1] No or Unknown Yes           No or Unknown
    -#> Levels: No or Unknown Yes
    -
    -
    -
    - -
    - - -
    - -
    -

    Site built with pkgdown 2.0.7.

    -
    - -
    - - - - - - - - diff --git a/docs/reference/make_yes_no_unknown.html b/docs/reference/make_yes_no_unknown.html deleted file mode 100644 index b711703..0000000 --- a/docs/reference/make_yes_no_unknown.html +++ /dev/null @@ -1,143 +0,0 @@ - -make_yes_no_unknown β€” make_yes_no_unknown β€’ tidyREDCap - - -
    -
    - - - -
    -
    - - -
    -

    Convert a "Yes-No", "True-False" or "Checkboxes (Multiple -Answers)" question in REDCap to a factor holding "No" or -"Yes" or "Unknown". Technically "yes" or "checked" (ignoring case), 1 or -TRUE responses are converted to "Yes". "No" or "unchecked" (ignoring -case), 0 or FALSE are converted to "No". All other values are set to -"Unknown". Also see make_yes_no().

    -
    - -
    -
    make_yes_no_unknown(x)
    -
    - -
    -

    Arguments

    -
    x
    -

    variable to be converted to hold "No", "Yes", or Unknown"

    - -
    -
    -

    Value

    - - -

    a factor with "No", "Yes", or Unknown"

    -
    - -
    -

    Examples

    -
    make_yes_no_unknown(c(0, 1, NA))
    -#> [1] No      Yes     Unknown
    -#> Levels: No Yes Unknown
    -make_yes_no_unknown(c("unchecked", "Checked", NA))
    -#> [1] No      Yes     Unknown
    -#> Levels: No Yes Unknown
    -
    -
    -
    - -
    - - -
    - -
    -

    Site built with pkgdown 2.0.7.

    -
    - -
    - - - - - - - - diff --git a/docs/reference/pipe.html b/docs/reference/pipe.html deleted file mode 100644 index 426635b..0000000 --- a/docs/reference/pipe.html +++ /dev/null @@ -1,111 +0,0 @@ - -Pipe operator β€” %>% β€’ tidyREDCap - - -
    -
    - - - -
    -
    - - -
    -

    See magrittr::%>% for details.

    -
    - -
    -
    lhs %>% rhs
    -
    - - -
    - -
    - - -
    - -
    -

    Site built with pkgdown 2.0.7.

    -
    - -
    - - - - - - - - diff --git a/docs/reference/taybull.html b/docs/reference/taybull.html deleted file mode 100644 index 2caf46e..0000000 --- a/docs/reference/taybull.html +++ /dev/null @@ -1,113 +0,0 @@ - -taybull function β€” taybull β€’ tidyREDCap - - -
    -
    - - - -
    -
    - - -
    -

    Make a labeled janitor table from a single variable

    -
    - -
    -
    taybull(variable, subset = FALSE)
    -
    - -
    -

    Arguments

    -
    variable
    -

    a factor to report on

    -
    subset
    -

    parse off extra variable if used with a choose all question

    -
    -
    -

    Value

    -

    a table

    -
    - -
    - -
    - - -
    - -
    -

    Site built with pkgdown 2.0.1.

    -
    - -
    - - - - - - - - diff --git a/docs/reference/taybull2.html b/docs/reference/taybull2.html deleted file mode 100644 index 32a4a01..0000000 --- a/docs/reference/taybull2.html +++ /dev/null @@ -1,116 +0,0 @@ - -taybull2 β€” taybull2 β€’ tidyREDCap - - -
    -
    - - - -
    -
    - - -
    -

    Make a labeled janitor table from a dataset and variable

    -
    - -
    -
    taybull2(data, aVariable, subset = FALSE)
    -
    - -
    -

    Arguments

    -
    data
    -

    a dataframe that has the factor to report on

    -
    aVariable
    -

    a factor to report on

    -
    subset
    -

    TRUE/FALSE used to remove the repeated text from of a -choose all that apply question

    -
    -
    -

    Value

    -

    a table

    -
    - -
    - -
    - - -
    - -
    -

    Site built with pkgdown 2.0.1.

    -
    - -
    - - - - - - - - diff --git a/docs/sitemap.xml b/docs/sitemap.xml deleted file mode 100644 index c44c2a5..0000000 --- a/docs/sitemap.xml +++ /dev/null @@ -1,93 +0,0 @@ - - - - /404.html - - - /LICENSE-text.html - - - /LICENSE.html - - - /articles/dropLabels.html - - - /articles/import_instruments.html - - - /articles/index.html - - - /articles/makeBinaryWord.html - - - /articles/makeChooseAllTable.html - - - /articles/makeChooseOneTable.html - - - /articles/makeInstrument.html - - - /articles/useAPI.html - - - /authors.html - - - /index.html - - - /news/index.html - - - /reference/dropTags.html - - - /reference/drop_label.html - - - /reference/drop_labels.html - - - /reference/getLabel2.html - - - /reference/import_instruments.html - - - /reference/index.html - - - /reference/make_binary_word.html - - - /reference/make_choose_all_table.html - - - /reference/make_choose_one_table.html - - - /reference/make_instrument.html - - - /reference/make_instrument_auto.html - - - /reference/make_yes_no.html - - - /reference/make_yes_no_unknown.html - - - /reference/pipe.html - - - /reference/taybull.html - - - /reference/taybull2.html - - diff --git a/man/drop_label.Rd b/man/drop_label.Rd index 78d7ade..3881b7d 100644 --- a/man/drop_label.Rd +++ b/man/drop_label.Rd @@ -2,20 +2,34 @@ % Please edit documentation in R/make_instrument_auto.R \name{drop_label} \alias{drop_label} -\title{Drop the label from a variable} +\title{Drop the label from one or more variables} \usage{ -drop_label(df, x) +drop_label(df, ...) } \arguments{ \item{df}{the name of the data frame} -\item{x}{the quoted name of the variable} +\item{...}{Variable selection using tidyselect helpers (e.g., \code{contains()}, +\code{starts_with()}) or column names as symbols or strings} } \value{ -df +df with labels removed from selected variables } \description{ -There is a reported issues with joins on data (without a reprex) -that seem to be caused by the labels. As a possible solution this can be -used to drop labels. +There is a reported issue with joins on data (without a reprex) +that seem to be caused by the labels. As a possible solution this can be +used to drop labels from one or more variables. +} +\examples{ +\dontrun{ +# Remove labels from a single variable +df |> drop_label(employment) + +# Remove labels from multiple variables +df |> drop_label(employment, marital_status) + +# Remove all demograhic labels using tidyselect helpers +df |> drop_label(starts_with("dem_")) +} + } diff --git a/tests/testthat/test-import_instruments.R b/tests/testthat/test-import_instruments.R index c799128..00983c6 100644 --- a/tests/testthat/test-import_instruments.R +++ b/tests/testthat/test-import_instruments.R @@ -10,8 +10,15 @@ target <- structure( list( record_id = structure( c(1, 2, 3, 4, 5), - label = "Study ID", - class = c("labelled", "numeric") + # 01.09.2026: REDCapR >= 1.2.0 returns tibbles instead of data.frames. + # Tibbles handle attributes differently than data.frames, causing the + # 'labelled' class and 'label' attribute to be stripped during data + # processing. Removed these attributes from test fixture to match actual + # REDCapR output behavior in tibble format. + # See: https://github.com/OuhscBbmc/REDCapR/releases/tag/v1.2.0 (#415) + # label = "Study ID", + # class = c("labelled", "numeric") + class = c("numeric") ), name_first = structure( c( diff --git a/vignettes/dropLabels.Rmd b/vignettes/dropLabels.Rmd index 2fcb496..4074f9a 100644 --- a/vignettes/dropLabels.Rmd +++ b/vignettes/dropLabels.Rmd @@ -106,7 +106,7 @@ If you would like to see the labels on the data set `demographics`, you can use View(demographics) ``` -![](./view_demog_w_labels_20230217.png){width=90%} +![Demographics preview with labels](./view_demog_w_labels_20230217.png){width=90%} However, some functions do not work well with labeled variables. ```{r skim-demo, error=TRUE} @@ -121,7 +121,7 @@ So you need a way to drop the label off of a variable or to drop all the labels You can drop the label from a single variable with the drop_label() function. For example: ```{r} -demographics_changed <- drop_label(demographics, "first_name") +demographics_changed <- drop_label(demographics, "name_first") ``` You can drop all the labels using the `drop_labels()` function. For example: diff --git a/vignettes/import_instruments.Rmd b/vignettes/import_instruments.Rmd index f8525c4..c57afd6 100644 --- a/vignettes/import_instruments.Rmd +++ b/vignettes/import_instruments.Rmd @@ -31,7 +31,7 @@ p.caption { Suppose you have a REDCap project with many instruments; some instruments are administered in some visits but not in others. In that case, the export from REDCap will have empty cells for the visits in which the instrument was not used. For example, Figure 1 shows a study where subjects completed four instruments (Enrollment, NCI, GAD7, and Hamilton) at baseline. On days 1, 2, and 3, they completed only Hamilton. At the end of the study, they completed NCI and Hamilton. The export of the data for this subject will have five records (one for each visit), and each record will have a cell for every existing instrument. However, the β€œNCI” record will only have values for the baseline and final visit and empty cells for the visits in between. On the other hand, there will be no empty spaces for the β€œHamilton” record as it was completed in all the visits. It would be good to have a function that will export all the data from a project and produce one R table for each instrument. Those tables should remove the blank records. \ \ -![](./dashboard.jpg) +![REDCap instrument status preview](./dashboard.jpg)

    Figure 1

    The same functionality should help deal with instruments that are potentially given repeatedly. Common examples include asking participants to fill out a form describing medical conditions for all their siblings or asking them to fill out a form for each side effect they experience while using a drug. In these cases, each participant may have zero or many records. Again, creating a table with all the records for these β€œrepeated” instruments would be good. @@ -61,10 +61,10 @@ The `import_instruments()` function can be given a URL and token for a REDCap pr After running the above code we get four tables from the REDCap project. -![](./global.jpg) +![RStudio Global Environment pane](./global.jpg) Notice that each repeat of the HAM-A is its own record. -![](./hama.jpg) +![HAM-A data preview using `View()`](./hama.jpg) If a person has only done the baseline assessment they will only have one record. diff --git a/vignettes/makeBinaryWord.Rmd b/vignettes/makeBinaryWord.Rmd index f52be82..28add45 100644 --- a/vignettes/makeBinaryWord.Rmd +++ b/vignettes/makeBinaryWord.Rmd @@ -28,7 +28,7 @@ REDCap exports a "choose all that apply" question into a series of similarly-nam > **Example:** In the Nacho Craving Index (NCI), respondents can indicate which of eight ingredients they are currently craving (i.e., Chips, Yellow cheese, Orange cheese, White cheese, Meat, Beans, Tomatoes, Peppers). These are exported into variables with names like `ingredients___1`, `ingredients___2`, etc. -In REDCap, it is simple to get a summary of those individual variables by using the "Data Exports, Reports, and Stats" application within the REDCap interface and selecting "Stats & Charts". Once the data is in R, simple tables can be produced with the `table()` function, or beautiful tables can be created with the `tabyl()` and `adorn_pct_formatting()` functions from the `janitor` package. However, from these univariate tables, it is impossible to judge which patterns of answers are marked together. In the above example, using the univariate tables, it is difficult to tell what percentage of people are craving both chips and yellow cheese. +In REDCap, it is simple to get a summary of those individual variables by using the "Data Exports, Reports, and Stats" application within the REDCap interface and selecting "Stats & Charts". Once the data is in R, simple tables can be produced with the `table()` function, or beautiful tables can be created with the `tabyl()` and `adorn_pct_formatting()` functions from the [`janitor`](https://sfirke.github.io/janitor/index.html) package. However, from these univariate tables, it is impossible to judge which patterns of answers are marked together. In the above example, using the univariate tables, it is difficult to tell what percentage of people are craving both chips and yellow cheese. ```{r univariate, warning=FALSE} redcap <- readRDS(file = "./redcap.rds") @@ -46,7 +46,7 @@ janitor::tabyl(redcap$ingredients___2) %>% ``` ## Aside: Loading REDCap Data into R -See the [Import All Instruments from a REDCap Project](../doc/importInstruments.html) and [Importing from REDCap](../doc/useAPI.html) vignettes for details/information. +See the [Import All Instruments from a REDCap Project](./import_instruments.html) and [Importing from REDCap](./useAPI.html) vignettes for details/information. # Make Analysis Data diff --git a/vignettes/makeChooseAllTable.Rmd b/vignettes/makeChooseAllTable.Rmd index 703a5c2..64292f8 100644 --- a/vignettes/makeChooseAllTable.Rmd +++ b/vignettes/makeChooseAllTable.Rmd @@ -34,7 +34,7 @@ redcap %>% It is desirable to have a concise table showing how often each option was chosen. ## Aside: Loading REDCap Data into R -See the [Import All Instruments from a REDCap Project](../doc/importInstruments.html) and [Importing from REDCap](../doc/useAPI.html) vignettes for details/information. +See the [Import All Instruments from a REDCap Project](./import_instruments.html) and [Importing from REDCap](./useAPI.html) vignettes for details/information. # The Solution diff --git a/vignettes/makeChooseOneTable.Rmd b/vignettes/makeChooseOneTable.Rmd index d6b4729..303dc37 100644 --- a/vignettes/makeChooseOneTable.Rmd +++ b/vignettes/makeChooseOneTable.Rmd @@ -37,7 +37,7 @@ table(redcap$ingredients___1) We no longer know what the question was or which "select all" option this information represents. ## Aside: Loading REDCap Data into R -See the [Import All Instruments from a REDCap Project](../doc/importInstruments.html) and [Importing from REDCap](../doc/useAPI.html) vignettes for details/information. +See the [Import All Instruments from a REDCap Project](./import_instruments.html) and [Importing from REDCap](./useAPI.html) vignettes for details/information. # The Solution The `make_choose_one_table()` function can be used with a factor variable to tabulate the response *while preserving the question and checked option context*. diff --git a/vignettes/makeInstrument.Rmd b/vignettes/makeInstrument.Rmd index 2e91ab3..49a0e64 100644 --- a/vignettes/makeInstrument.Rmd +++ b/vignettes/makeInstrument.Rmd @@ -27,7 +27,7 @@ library(dplyr) REDCap exports longitudinal projects with one record (a line of data) per assessment (typically 1 line per day). This works well when every instrument/questionnaire is given at every assessment. Still, for projects with different instruments/questionnaires given on different days, REDCap exports empty values (represented by the value `NA` in R). > **Example:** In the Nachos for Anxiety project, three instruments were used; they each had a different administration schedule. Subjects' anxiety was assessed at baseline with the Generalized Anxiety Disorder 7-item (GAD-7) scale. Every day, it was assessed with the Hamilton Anxiety Scale (HAM-A), but the Nacho Craving Index was administered only at the baseline and at the end of the study (see the figure below for clarification). -![](./schedule.png) +![Nacho Craving Index administration schedule](./schedule.png) The instruments that are not assessed every day appear as entirely blank questionnaires when the data is exported. For example, values from the NCI instrument are shown as missing for Day 1, Day 2, and Day 3 (because it was not administered during those visits). @@ -49,7 +49,7 @@ redcap %>% It is often helpful to make a different data table that has the values for each questionnaire without the blank records. ## Aside: Loading REDCap Data into R -See the [Import All Instruments from a REDCap Project](../doc/importInstruments.html) and [Importing from REDCap](../doc/useAPI.html) vignettes for details/information. +See the [Import All Instruments from a REDCap Project](./import_instruments.html) and [Importing from REDCap](./useAPI.html) vignettes for details/information. # The Solution diff --git a/vignettes/useAPI.Rmd b/vignettes/useAPI.Rmd index 401e1f6..86545a8 100644 --- a/vignettes/useAPI.Rmd +++ b/vignettes/useAPI.Rmd @@ -23,15 +23,13 @@ While most people use the "Data Exports, Reports and Stats" Application built in We have used two R packages to access our REDCap projects,`redcapAPI` and `REDCapR`. Unfortunately, `redcapAPI` is no longer being actively developed, and we have run into problems with it. It had the lovely benefit of exporting variables, basically using the same variable names as you see in REDCap, then tagging the variables with the "labels" subjects viewed when completing the forms. -that people taking REDCap surveys or viewing other forms see. - We have taken the labeling functionality and added it in tidyREDCap. ### Getting an API Token If your REDCap project has API access enabled, you will see it in the applications on the left side of the screen. -![](./key.jpg) +![How to obtain an API key from the REDCap dashboard](./key.jpg) If you don't see that option, talk to your project leader or the REDCap system administrator. @@ -104,7 +102,7 @@ rcon <- redcapAPI::redcapConnection( redcap <- redcapAPI::exportRecords(rcon) ``` -This includes a call to `Sys.getenv()` to grab the key. To learn more about working with APIs, look [here](https://daattali.gitbooks.io/stat545-ubc-github-io/bit003_api-key-env-var.html). +This includes a call to `Sys.getenv()` to grab the key. To learn more about working with APIs, look [here](https://daattali.gitbooks.io/stat545-ubc-github-io/content/bit003_api-key-env-var.html). If you are curious, when we made these help files, we saved the data using the `saveRDS()` function. @@ -124,4 +122,4 @@ saveRDS(redcap, file = "redcap.rds")
    ### Even Better Options -If somebody gets access to the files on your machine, they could find and read your .Renviron file. A more secure option is to use the r `keyring` package. It will store an encrypted copy of your API key in your machine's credential store (i.e., the "keychain" on macOS, the Credential Store on Windows, etc.). Consider using it. If you use it and your machine is stolen, it will buy you more time to find an internet connection, log into REDCap and change your API tokens (before the thief can access your data). \ No newline at end of file +If somebody gets access to the files on your machine, they could find and read your .Renviron file. A more secure option is to use the r `keyring` package. It will store an encrypted copy of your API key in your machine's credential store (i.e., the "keychain" on macOS, the Credential Store on Windows, etc.). Consider using it. If you use it and your machine is stolen, it will buy you more time to find an internet connection, log into REDCap and change your API tokens (before the thief can access your data).