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)
})
}# formr's writing functions never default to your working directory. Set a
# session default once (here a temp dir) — or pass dir=/save_path= per call.
formr_default_dir(tempdir())
#> [1] "/tmp/Rtmpku4mBo"
formr_default_dir()
#> [1] "/tmp/Rtmpku4mBo"Version 0.12.0 of the formr package introduces a robust
workflow for managing your studies locally. Instead of uploading files
one by one on the website, you can now sync your entire project folder.
This makes it possible to use Git for version control and your preferred
local editors for Excel, CSS, and JavaScript files.
Ensure you have stored your API credentials as described in the Getting Started guide.
Before making major changes, it is good practice to create a full backup of your run. This function downloads the run structure (JSON), all survey item tables (Excel), attached files (images/scripts), and the current results.
# Not run: needs a live formr server.
# Download everything to a folder named "backup_my_study"
formr_api_backup_run("my-study-name", dir = tempdir())This creates a self-contained archive of your study state at that moment.
The recommended workflow for active development is Pull -> Edit -> Push.
First, create a local directory for your project and pull the current state from the server. This scaffolds the necessary folder structure.
# Not run: needs a live formr server.
# Pull the project into a local folder
formr_api_pull_project("my-study-name", dir = tempdir())This will create the following structure:
surveys/: Contains your survey spreadsheets
(.xlsx).
files/: Contains images and other assets.
css/ & js/: Contains your custom
styling and scripts.
run_settings.json: Configuration like privacy
settings and data expiration.
run_structure.json: The flow of your run (surveys,
pauses, emails).
You can now edit these files using your favorite tools:
Open .xlsx files in Excel/LibreOffice.
Edit .css and .js in VS Code or
RStudio.
Add new images to the files/ folder.
Once you are happy with your local changes, push them back to the server. The function compares file modification times and only uploads what has changed.
# Not run: needs a live formr server.
# Sync local changes to the server
formr_api_push_project("my-study-name", dir = tempdir())If you are heavily editing a survey, running
formr_api_push_project manually every time can be tedious.
You can use the watch argument to keep the connection open.
The package will monitor your folder and upload changes immediately as
you save files. Note that you can run other commands in your R session,
as the watcher launches as a background job. You can stop the watcher by
terminating the background process.
You can also view and update run settings programmatically. This is
useful for toggling specific flags like public or
locked without navigating the UI.
For advanced users, the entire flow of the run (the “Unit” list) can be exported and imported as JSON. This allows you to template complex study designs or import them directly.