R/high_level_functions.R
prepare_for_public_release.Rdtrials_results is a trials tibble containing data that needs to be
anonymized and cleaned before public release.
prepare_for_public_release(
trials_results,
force_retain = NULL,
force_remove = NULL,
output_report = NULL,
drop_file_cols = TRUE,
drop_expression_cols = TRUE,
shuffle_seed = NULL
)A trials tibble or data frame, possibly grouped.
A character vector of column names to exclude from removal,
overriding automatic detection. Useful for retaining specific questionnaire items
or other sensitive columns. (Default: NULL)
A character vector of column names to remove in addition to
automatically detected columns. (Default: NULL)
Path to a text file where the preparation report should be
written. If NULL, the report is printed to console. (Default: NULL)
Flag indicating whether file columns should be dropped (Default: TRUE)
Flag indicating whether expression columns should be dropped (Default: TRUE)
An integer seed for reproducible shuffling of ppids and row order.
If NULL, shuffling is random. (Default: NULL)
A tibble with the same row count as trials_raw, fewer columns, and with the ppid
column replaced by .ppid_shuffled. The tibble has two additional attributes:
public_release_report: A list containing details of all removals and changes
report_text: A formatted character string of the report suitable for printing
This function removes movement data columns, questionnaire columns, data file location columns
force_retain takes precedence over force_remove.
ppid, screenrec_filename, lsltriggerrecorder_filepath, res_path and
"camrec_filename" are removed always (regardless of force_retain)
Movement data columns are identified by two criteria:
Column names containing "movement_data"
Columns with nested tibbles containing "pos_" columns
Botheyes tracking data columns
Questionnaire item columns are identified by the pattern <questionnaire_name>_<number>
and/or contains "redcap" in the name.
(e.g., mccs_1, mccs_2, sticsa_s_1). Aggregated questionnaire scores are retained.
Location columns are detected by presence of "location_0", "filename" or "filepath"
Expression columns are defined as those columns with names that are a function call of some kind
example if_else(is.na(previous_trial), 0, previous_trial), calls to is.na, case_when etc.
Detection checks for a valid function name followed by an openning parenthesis (.
# Basic usage: prepare data for release
data_public <- prepare_for_public_release(example_trials)
#> Error: object 'example_trials' not found
# With report saved to file
data_public <- prepare_for_public_release(
example_trials,
output_report = "release_report.txt"
)
#> Error: object 'example_trials' not found
# Force-retain specific questionnaire items while removing others
data_public <- prepare_for_public_release(
example_trials,
force_retain = c("mccs_1", "mccs_2"),
shuffle_seed = 42
)
#> Error: object 'example_trials' not found