library(formr)
# So this vignette runs offline, API calls are replayed from pre-recorded
# responses (vcr cassettes shipped with the package). With a real server you
# would instead call formr_api_authenticate() with your own host/credentials.
.formr_vcr <- requireNamespace("vcr", quietly = TRUE) &&
nzchar(system.file("extdata/vcr_cassettes", package = "formr"))
if (.formr_vcr) {
vcr::vcr_configure(
dir = system.file("extdata/vcr_cassettes", package = "formr"),
filter_sensitive_data = list(
"formr-client-id-redacted" = "dummy_client_id",
"formr-client-secret-redacted" = "dummy_client_secret",
"formr-host-redacted" = "api.localhost"
)
)
vcr::use_cassette("formr_api_authenticate", {
formr_api_authenticate(host = "http://api.localhost",
client_id = "dummy_client_id", client_secret = "dummy_client_secret",
verbose = FALSE)
})
}Managing sessions is a critical part of maintaining a study. Whether you are debugging an issue with a participant, cleaning up test data, or generating codes for participants, the formr package provides tools to inspect and control sessions directly from R.
To get an overview of who is currently in your study, use
formr_api_sessions(). This function returns a tidy data
frame containing session codes, their current position in the run, and
timestamps.
You can filter sessions to see only those that are currently active or those marked as test sessions.
For runs with many sessions, use limit and
offset to page through results (default limit is 1000).
If you know a participant’s session code (e.g., from a user report), you can fetch their details directly to see exactly where they are.
While users typically create their own sessions by clicking a link, you might need to generate sessions programmatically. This is common for:
Sometimes you need to intervene in a participant’s progress. The
formr_api_session_action() function allows you to modify
the state of one or more sessions.
If a bug or logic error causes a user to get stuck at a specific point, you can manually move them to a different unit in the run.
If you accidentally performed a self-test with a “real” session code, or if a real participant used a test code, you can toggle the testing flag. This helps keep your data clean/separate.