Setting Up Sessions with R Initializers

In some situations you want to run an R expression once, such as to initialize the R environment with some variables or data frames. To run something at the start of a session, you can run an expression in a session variable. Repository variables are run only on demand so if they aren’t referred to, they won’t work. Use a session variable.

The session variable must exist prior to using the REXP method for Calling R Inline in a Report or ETL Script.

The example below shows how a session variable is utilized to instantiate the model.

See Creating Variables for information about how to create a variable in Birst.

Tip: In R, to create a model if it doesn’t exist (which is handy for conditionally instantiating something), use the following:

if (exists("model")) "exists" else model<-lm(formula=speed~dist,cars)

Next Steps

Calling R Inline in a Report or ETL Script