Initializes the tracking database, optionally loads a tracking configuration,
registers the current learner, and returns a small context object. The context
can then be passed to tracked_question(), tracked_question_radio(),
tracked_question_checkbox(), tracked_question_text(),
tracked_question_numeric(), track_gradethis_attempt(), and
open_learnr_tracking_db().
Usage
setup_learnr_tracking(
tutorial_id,
student_id = get_tracking_student_id(),
db_path = Sys.getenv("LEARNRTRACKR_DB", unset = file.path(tempdir(),
paste0(tutorial_id, ".sqlite"))),
group_id = Sys.getenv("LEARNRTRACKR_GROUP_ID", unset = NA_character_),
config_path = NULL,
student_label = student_id,
overwrite = FALSE,
register_student = TRUE
)Arguments
- tutorial_id
Tutorial identifier stored in the tracking database.
- student_id
Student identifier. Defaults to
get_tracking_student_id().- db_path
Path to the SQLite tracking database. Defaults to the
LEARNRTRACKR_DBenvironment variable, or a temporary SQLite file based ontutorial_idwhen the variable is missing.- group_id
Optional learner group. Defaults to the
LEARNRTRACKR_GROUP_IDenvironment variable, orNA_character_.- config_path
Optional YAML file or CSV directory loaded with
load_tracking_config(). UseNULLto skip configuration loading.- student_label
Optional label for the current learner. Defaults to
student_id.- overwrite
If
TRUE, remove an existing SQLite database before initialization.- register_student
If
TRUE, register the current learner in thestudentstable.
Details
This helper is intended for the setup chunk of a learnr tutorial. It keeps
the tutorial code explicit while avoiding repeated student_id,
tutorial_id, and db_path arguments in each tracked question.
Examples
db_path <- tempfile(fileext = ".sqlite")
tracking <- setup_learnr_tracking(
tutorial_id = "module_01",
student_id = "student_001",
db_path = db_path
)
con <- open_learnr_tracking_db(tracking)
DBI::dbDisconnect(con)