R6 project object for REDCapSync
This is the main class for managing REDCap data, metadata, and sync
operations. Users should construct objects using setup_project(). To reopen
an existing project, use load_project() or explore offline examples using
load_test_project().
See also
setup_project for initializing the project object.'
Active bindings
project_nameRead-only character string of project_name as assigned from setup_project.
dir_pathRead-only directory path assigned from setup_project.
dataRead-only named list where each name is an instrument name. See public methods for REDCapSync_project.
metadataRead-only named list with REDCap metadata. See public methods for REDCapSync_project.
redcapRead-only named list with REDCap information including users and log.
.internalRead-only internal project object for custom workflows
Methods
Method new()
Active binding are read-only
The end user will not see project$new(). This is handled internally.
Users should construct objects using setup_project(). The remain
methods will be accessible to any user.
Usage
REDCapSync_project$new(project)Method sync()
Updates the REDCap data for (project object) by checking REDCap log for
changes. Sync is performed according to the sync_frequency set in
setup_project() by default. Use hard_check to force a check, or hard_reset to force a complete refresh.
Usage
REDCapSync_project$sync(
summarize = TRUE,
save_to_dir = TRUE,
hard_check = FALSE,
hard_reset = FALSE
)Arguments
summarizeLogical (TRUE/FALSE). If TRUE, summarizes data to directory.
save_to_dirLogical (TRUE/FALSE). If TRUE, saves the updated data in the project object to the directory at
dir_path. Ignored whendir_pathisNULL. Default isTRUE.hard_checkWill check REDCap even if not due (see
sync_frequencyparameter fromsetup_project())hard_resetLogical. If
TRUE, overwrite existing summary files with the same name. Default isFALSE.
Method add_summary()
Add a new summary entry
Usage
REDCapSync_project$add_summary(
summary_name,
transformation_type = "default",
merge_form_name = "merged",
filter_field = NULL,
filter_choices = NULL,
filter_list = NULL,
filter_strict = TRUE,
field_names = NULL,
form_names = NULL,
exclude_identifiers = TRUE,
exclude_free_text = FALSE,
date_handling = "none",
labelled = TRUE,
clean = TRUE,
drop_blanks = FALSE,
drop_missing_codes = FALSE,
drop_others = NULL,
include_metadata = TRUE,
include_records = TRUE,
include_users = TRUE,
include_log = FALSE,
annotate_from_log = TRUE,
with_links = TRUE,
separate = FALSE,
use_csv = FALSE,
dir_other = NULL,
file_name = NULL,
hard_reset = FALSE
)Arguments
summary_nameCharacter. The name of the configured summary from which to generate the summary. *If you provide
summary_nameall other parameters are inherited according to what was set withadd_project_summary.transformation_typeCharacter scalar. How to transform data for the summary. Default is "default". Other options are "none", "flat", "merge_non_repeating". "default" first merges non-repeating and if there are repeating forms, it merges non-repeating variables to the right of repeating instruments. "flat" is one-record, one-row, even if there are repeating forms. "none" does not transform anything. "merge_non_repeating" still merges all non-repeating instruments but does not merge them to repeating instruments.
merge_form_nameA character string representing the name of the merged form. Default is "merged".
filter_fieldCharacter. The name of the field in the database to filter on. Used with
filter_choices.filter_choicesVector. The values of
filter_fieldused to define the summary. An alternative to providing a fullfilter_list.filter_listVector. The values of
filter_fieldused to define the summary. Names are field names; values are the allowed value set(s). Use eitherfilter_listorfilter_fieldwithfilter_choices.filter_strictLogical. If
TRUE, all forms will be filtered by criteria. IfFALSE, will convert original filter to ID column and filter all other forms by that record. Default isTRUE.field_namesCharacter vector. Names of specific fields to include in the summary. Default is
NULL, which includes all fields.form_namesCharacter vector. Names of forms to include in the summary. Default is
NULL, which includes all forms.exclude_identifiersLogical. Whether to exclude identifiers in the data in the summary. Default is
TRUE.exclude_free_textLogical. If
TRUE, exclude free text fields intended for de-identification workflows. Default isFALSE.date_handlingcharacter string. One of
none,exclude_dates,random_shift_by_record,random_shift_by_project,zero_by_record, orzero_by_project. Random shift is +/- 90 unless changed with options.labelledLogical. If
TRUE, the data will be converted to labelled. IfFALSE, returns raw coded values. Default isTRUE.cleanLogical. If
TRUE, the data will be cleaned (e.g., standardizing missing/blank values) before summarizing. Default isTRUE. If missing codes are present in a number or date variable, R will convert missing codes to NA and will make that variable not upload compatible.drop_blanksLogical. If
TRUE, records with blank fields will be dropped during cleaning. Default isTRUE.drop_missing_codesLogical. If
TRUE, will convert missing codes to NA. Default isFALSE.drop_othersCharacter vector of other values that should be dropped.
include_metadataLogical. If
TRUE, metadata will be included in the summary. Default isTRUE.include_recordsLogical. If
TRUE, a record summary will be included in the generated summary. Default isTRUE.include_usersLogical. If
TRUE, user-related information will be included in the summary. Default isTRUE.include_logLogical. If
TRUE, the log of changes will be included in the summary. Default isTRUE.annotate_from_logLogical. If
TRUE, the metadata, users, and records will be annotated using the log. Default isTRUE.with_linksOptional logical (TRUE/FALSE) for including links in Excel sheets. Default is
FALSE.separateOptional logical (TRUE/FALSE) separating each form into separate files as opposed to multi-tab Excel. Default is
FALSE.use_csvLogical (TRUE/FALSE). If TRUE, uses CSV files for data storage. Default is
FALSEdir_otherCharacter. The directory where the summary file will be saved. Default is the
outputfolder within the database directory.file_nameCharacter. The base name of the file where the summary will be saved. Default is
<project_name>_<summary_name>.hard_resetLogical. If
TRUE, overwrite existing summary files with the same name. Default isFALSE.
Method add_field()
Add a new summary entry
Usage
REDCapSync_project$add_field(
field_name,
form_name,
field_type,
field_type_R = NA,
field_label = NA,
select_choices_or_calculations = NA,
field_note = NA,
identifier = "",
units = NA,
data_func = NA
)Arguments
field_nameCharacter. The name of the field to which the transformation will be applied.
form_nameCharacter. The name of the form containing the field.
field_typeCharacter. The type of the field in REDCap (e.g., "text", "checkbox", "dropdown").
field_type_RCharacter. The corresponding R data type for the field. Default is
NA.field_labelCharacter. The label for the field. Default is
NA.select_choices_or_calculationsCharacter. A string specifying the choices (for dropdown, radio, or checkbox fields) or calculations (for calculated fields). Default is
NA.field_noteCharacter. An optional note or comment for the field. Default is
NA.identifierCharacter. A string indicating whether the field is an identifier (e.g., "Y" for yes). Default is an empty string (
"").unitsCharacter. The units of measurement for the field, if applicable. Default is
NA.data_funcFunction or NA. An optional function to transform or validate the data in the field. Default is
NA.
