View source: R/parse-field-labels-academic.R
parse_field_labels_academic | R Documentation |
Take the field names and field labels that are given in the script from REDCap academic and parse them into a 'tbl_df' with columns for all of the information. This is usefule because later on these can be used to make pretty (or human readable) field names and feild labels in tables with the REDCap variables. Also, parses the checkbox choices from radio style variables in the data base.
Best pracitce is to copy the text from the REDCap script and paste it as a veritcal vector using the 'datapasta' package by Miles McBain. (https://cran.r-project.org/web/packages/datapasta/index.html). See example.
parse_field_labels_academic(
data,
text = text,
checkbox_text = c("Choose all that apply.", "Mark all that apply.")
)
data |
A data frame or tibble with a single column with the text from the R file that is exported from REDCap. |
text |
Name of the column. Default is 'text'. |
checkbox_text |
Character string of text to remove from the labels for checkbox style variables. Default is 'c("Choose all that apply.", "Mark all that apply.")' |
A 'tbl_df' with the following columns:
REDCap variable names
REDCap labels for the variables
REDCap labels that have been cleaned to remove extra text
Options for checkbox type variables
TRUE/FALSE is this variable a checkbox
#### Step 1. Paste labels --------------------------------
# Copy the labels from the REDCap script.
# Using the data pasta add-in, paste as a vertical vector.
# Add the necessary syntax to make this a tbl_df.
data_labels <- tibble::tibble(
text = # Paste as vertical vector
c("label(data$record_id)=\"Record ID\"",
"label(data$gender)=\"What is your gender?\"",
"label(data$gender_other)=\"Prefer to self-describe:\"",
"label(data$age)=\"What is your age?\"",
"label(data$education)=\"What is the highest level of education you have completed? Mark only one.\"",
"label(data$ethnicity)=\"Would you describe yourself as being of Hispanic or Latino/a origin or descent?\"",
"label(data$race___1)=\"How would you describe your race? Mark all that apply. (choice=White)\"",
"label(data$race___2)=\"How would you describe your race? Mark all that apply. (choice=Black or African-American)\"",
"label(data$race___3)=\"How would you describe your race? Mark all that apply. (choice=American Indian or Alaska Native)\"",
"label(data$race___4)=\"How would you describe your race? Mark all that apply. (choice=Asian)\"",
"label(data$race___5)=\"How would you describe your race? Mark all that apply. (choice=Native Hawaiian or Pacific Islander)\"",
"label(data$race___6)=\"How would you describe your race? Mark all that apply. (choice=Other)\"",
"label(data$race___98)=\"How would you describe your race? Mark all that apply. (choice=Prefer not to answer)\"",
"label(data$race_other)=\"Other (tell us):\"",
"label(data$income)=\"What was your total household income (before taxes) last year (2018)? Your best estimate is fine.\"",
"label(data$marital_status)=\"What is your marital status?\"",
"label(data$survey_complete)=\"Complete?\"")
)
#### Step 2. Make the tbl_df with the labels --------------------------------
data_labels <- data_labels %>%
parse_field_labels_academic(.)
data_labels
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.