Make R-models compatible with Chap
This page covers how to set up the environment for R-based models using renv.
Environment options
renv environment (for R models)
Use renv_env to specify an renv.lock file for R models that use renv for dependency management:
When Chap runs your model, it will automatically:
- Look for the
renv.lockfile in your model directory - Run
renv::restore(prompt = FALSE)to install all required R packages - Execute your R commands with the restored environment
Your model directory should contain:
renv.lock- The lockfile specifying exact package versions (generated byrenv::snapshot())renv/directory - Contains renv activation scripts.Rprofile- Auto-activates renv when R starts (typically containssource("renv/activate.R"))
Setting up renv for your R model
-
Initialize renv in your R project:
-
Install your required packages:
-
Create the lockfile:
This creates renv.lock with exact versions of all dependencies, ensuring reproducible environments.
See the minimalist R model example for a complete working example.
Next steps
- For prediction length constraints and configurable model parameters, see Additional Configuration