R6 object representing a standardized dataset generated from
a REDCapSync project. Use this object to inspect transformed REDCap data,
export datasets, and assign prepared analysis tables into the calling
environment.
Value
An R6 REDCapSyncDataset object containing dataset output, metadata,
records, user information, and optional REDCap log data.
Details
A REDCapSyncDataset can be created ad-hoc from a project with
dataset <- project$generate_dataset(). For reusability, you can also
define with project$add_dataset() and then load with
dataset <- project$load_dataset().
You can add variables manually if you want them to be passed to Excel. But
add_field is a feature in development.
Typical workflow
setup project from test object
project <- setup_project(
project_name = "TEST_CLASSIC",
dir_path = tempdir()
)
# Create and save a filtered dataset
project$add_dataset(
dataset_name = "analysis_set",
filter_field = "var_yesno",
filter_choices = "Yes",
field_names = c("ecog_at_diagnosis", "stage_at_diagnosis")
)
# generate dataset for R environment
dataset <- project$load_dataset("analysis_set")
# optional send to global environment
dataset$to_envir(globalenv()) # keep in mind potential name conflicts
# Optional modify (final save depends on what is in the dataset object)
dataset$data$merged$stage_2 <- dataset$data$merged$stage_at_diagnosis == "II"
# save to directory
dataset$save() # can specify `dir_other`, by default saves to output folder
This object is designed for users who want a stable dataset output from REDCap without modifying the underlying project. This is also used behind-the-scenes in the RosyREDCap shiny app.
See also
project for using the project objects
vignette("Datasets", package = "REDCapSync")
vignette("RosyREDCap", package = "REDCapSync")
Public fields
datalist of data where names are forms
metadatalist of metadata
recordsdata.frame of records with timestamps
usersdata.frame of users with timestamps
logdata.frame of log
commentsdata.frame of comments
Active bindings
project_detailsRead-only list of dataset details from
setup_project().dataset_detailsRead-only list of dataset details
redcapRead-only list of dataset details from project
linksRead-only list of dataset details from project
Methods
REDCapSyncDataset$new()
The end user will not see dataset$new(). This is handled internally.
Users should construct objects using REDCapSyncProject.
Usage
REDCapSyncDataset$new(
project,
dataset_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 = FALSE,
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_users = TRUE,
include_records = TRUE,
include_log = FALSE,
annotate_from_log = TRUE,
include_comments = FALSE
)Arguments
projectProject object from
setup_project()orload_project().dataset_nameCharacter. Name of the dataset to generate or load. If the dataset already exists in the project, the existing definition is reused.
transformation_typeCharacter. Data transformation strategy: "default" (preferred merged output), "none" (raw data structure), or "merge_non_repeating" (merge only non-repeating forms). Default is "default".
merge_form_nameCharacter. Name used for merged non-repeating records. Default is "merged".
filter_fieldCharacter. Field used for filtering the dataset.
filter_choicesVector. Allowed values for
filter_field.filter_listList. Named list mapping field names to allowed values. Use instead of
filter_field/filter_choicesfor more complex filters.filter_strictLogical. If
TRUE, filters are applied to every form. IfFALSE, filters apply only to the record identifier. Default isTRUE.field_namesCharacter vector. Variables to include in the dataset. Default is
NULL(all fields).form_namesCharacter vector. Forms to include in the dataset. Default is
NULL(all forms).exclude_identifiersLogical. Remove identifier fields. Default is
TRUE.exclude_free_textLogical. Remove free text fields. Default is
FALSE.date_handlingCharacter. Date handling method: "none", "exclude_dates", "random_shift_by_record", "random_shift_by_project", "zero_by_record", or "zero_by_project". Default is "none".
labelledLogical. Convert values to labelled vectors if
TRUE. Default isTRUE.cleanLogical. Clean the dataset by standardizing missing values and blanks. Default is
TRUE.drop_blanksLogical. Drop records with blank fields. Default is
FALSE.drop_missing_codesLogical. Convert REDCap missing codes to
NA. Default isFALSE.drop_othersCharacter vector of additional values to remove.
include_metadataLogical. Include field metadata in the dataset. Default is
TRUE.include_usersLogical. Include user information in the dataset. Default is
TRUE.include_recordsLogical. Include record-level details. Default is
TRUE.include_logLogical. Include REDCap activity log details. Default is
FALSE.annotate_from_logLogical. Annotate metadata and records using the change log. Default is
TRUE.include_commentsLogical. Include REDCap comments. Default is
FALSE.
REDCapSyncDataset$save()
Return flat list
Usage
REDCapSyncDataset$save(
with_links = TRUE,
separate = FALSE,
use_csv = FALSE,
dir_other = NULL,
file_name = NULL
)Arguments
with_linksLogical. Include hyperlinks in Excel exports. Default is
TRUE.separateLogical. Save each form as a separate file instead of a multi-sheet workbook. Default is
FALSE.use_csvLogical. Write CSV files instead of Excel. Default is
FALSE.dir_otherCharacter. Directory where the dataset file should be saved. Defaults to the project's output folder.
file_nameCharacter. Base file name for saved datasets. Defaults to
<project_name>_<dataset_name>.
Examples
project <- load_project("TEST_CLASSIC")
#> ! No cached projects... use `setup_project(...)`
#> ✔ Loaded TEST project TEST_CLASSIC!
#> ! Does not actually communicate with any REDCap API
dataset <- project$generate_dataset(
dataset_name = "stage_2_patients",
filter_field = "stage_at_diagnosis",
filter_choices = "II",
field_names = c("ecog_at_diagnosis", "stage_at_diagnosis")
)
dataset$save(dir_other = tempdir())
#> ✔ Saved TEST_CLASSIC_stage_2_patients.xlsx: /tmp/RtmpXOajNj/TEST_CLASSIC_stage_2_patients.xlsx
