Recursively loads and joins trial-level data (usually additional movement data recorded outside Unity, e.g., MoCap data) to an existing tibble. Matches files based on ppid, session_num, and trial_num, using both folder structure and filename information. File names and file tree must follow a standard format (see below).

join_data(
  trial_results,
  processed_base_folder,
  column_name = "processed_movement_data",
  verbose = FALSE
)

Arguments

trial_results

A data frame or tibble containing trial-level metadata with columns ppid, session_num, and trial_num.

processed_base_folder

A character string specifying the path to the base folder containing processed .csv movement files.

column_name

A character string giving the name for the new column containing nested tibbles of movement data. Default is "processed_movement_data".

verbose

Whether to save a csv of unmatched files

Value

A tibble: the original trial_results with an added column (named by column_name) containing nested data frames of csv data, and a column ((named by column_name + "_filepath") with the source path of this nested tibble Files that could not be matched or read are skipped, with warnings shown.

Details

  • File name must start with "T" (for trial), followed by the trial number

  • Files starting with "R" (for run) are actively ignored (e.g., R001_vrthreat.csv), as they refer to data not recorded trial-by-trial

  • Session numbers are inferred either from the folder name (.../1_2/S001/...) or directly from the session folder (.../1/S002/...).

  • Trial numbers are extracted from filenames like T034_*.csv.

  • Data loading is performed safely with purrr::possibly() to avoid stopping on corrupted files.

Examples

if (FALSE) { # \dontrun{
df_with_movement <- join_data(
  trial_results = trial_results,
  processed_base_folder = ".../study5/processed/vrthreat_reformatted",
  column_name = "processed_movement_data"
)
} # }