Skip to contents

Reads the student identifier from an environment variable. This helper is intended for minimal learnr prototypes where the learner identity is passed to the tutorial before launch.

Usage

get_tracking_student_id(
  envvar = "LEARNRTRACKR_STUDENT_ID",
  default = NULL,
  required = TRUE
)

Arguments

envvar

Name of the environment variable that stores the student identifier. Defaults to "LEARNRTRACKR_STUDENT_ID".

default

Optional fallback identifier used when the environment variable is missing or empty.

required

If TRUE, throw an informative error when no identifier is available. If FALSE, return NA_character_ when no identifier is available.

Value

A character scalar student identifier, or NA_character_ when required = FALSE and no identifier is available.

Examples

withr::local_envvar(LEARNRTRACKR_STUDENT_ID = "student_001")
get_tracking_student_id()
#> Error in get_tracking_student_id(): Student identifier is missing.
#>  Set the `LEARNRTRACKR_STUDENT_ID` environment variable before launching the
#>   tutorial.
#>  Example: `Sys.setenv(LEARNRTRACKR_STUDENT_ID = "student_001")`.

get_tracking_student_id(default = "student_demo")
#> [1] "student_demo"