Title: | Helper Functions for Working with 'REDCap' Data |
---|---|
Description: | Helper functions for processing 'REDCap' data in R. 'REDCap' is a web-enabled application for building and managing surveys and databases developed at Vanderbilt University. |
Authors: | Raymond Balise [aut, cre] , Gabriel Odom [aut] , Anna Calderon [aut] , Layla Bouzoubaa [aut] , Wayne DeFreitas [aut] , Lauren Nahodyl [ctb] , Kyle Grealis [aut] |
Maintainer: | Raymond Balise <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.1.2 |
Built: | 2024-11-15 05:53:15 UTC |
Source: | https://github.com/raymondbalise/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)
drop_label(df, x)
df |
the name of the data frame |
x |
the quoted name of the variable |
df
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)
drop_labels(df)
df |
The data frame with column labels that you want to drop |
df without column labels
## Not run: demographics |> drop_labels() |> skimr::skim() ## End(Not run)
## Not run: demographics |> drop_labels() |> skimr::skim() ## End(Not run)
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 )
import_instruments( url, token, drop_blank = TRUE, record_id = "record_id", first_record_id = 1, envir = .GlobalEnv )
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 |
first_record_id |
A value of the custom |
envir |
The name of the environment where the tables should be saved. |
one data.frame
for each instrument/form in a REDCap project. By
default the datasets are saved into the global environment.
## Not run: import_instruments( "https://redcap.miami.edu/api/", Sys.getenv("test_API_key") ) ## End(Not run)
## Not run: import_instruments( "https://redcap.miami.edu/api/", Sys.getenv("test_API_key") ) ## End(Not run)
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)
make_binary_word(df, yes_value = "Checked", the_labels = letters)
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 |
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. |
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.
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)
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)
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)
make_choose_all_table(df, variable)
df |
The name of the data set (it needs labels) |
variable |
The name of the REDCap variable |
A variable's response label without the choose all the question
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)
make_choose_one_table(arg1, arg2, subset = FALSE)
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. |
a table
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" )
make_instrument( df, first_var, last_var, drop_which_when = FALSE, record_id = "record_id" )
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 |
Name of |
A data frame that has an instrument (with at least one not NA value)
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")
make_instrument_auto(df, drop_which_when = FALSE, record_id = "record_id")
df |
A data frame with the instrument |
drop_which_when |
Drop the |
record_id |
Name of |
A data frame that has an instrument (with at least one not NA value).
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)
make_yes_no(x)
x |
x variable to be converted to hold "Yes" or "No or Unknown" |
a factor with "Yes" or "No or Unknown"
make_yes_no(c(0, 1, NA)) make_yes_no(c("unchecked", "Checked", NA))
make_yes_no(c(0, 1, NA)) make_yes_no(c("unchecked", "Checked", NA))
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)
make_yes_no_unknown(x)
x |
variable to be converted to hold "No", "Yes", or Unknown" |
a factor with "No", "Yes", or Unknown"
make_yes_no_unknown(c(0, 1, NA)) make_yes_no_unknown(c("unchecked", "Checked", NA))
make_yes_no_unknown(c(0, 1, NA)) make_yes_no_unknown(c("unchecked", "Checked", NA))