MicroStrategy ONE

The R Integration Pack is no longer supported as of December 2024.

Saving the R Workspace

R can save its workspace to the file system. This is helpful when you need to review the results of an analysis. When you execute a script from the R console, you can easily inspect the state of the workspace and its objects. It is helpful to capture the R workspace when MicroStrategy executes the script. The workspace is a valuable tool for the R developer to use when troubleshooting problems or verifying results.

An example of code inserted to save a workspace is shown below. The addition (the last line in the example) to the R script shown below saves objects from the R workspace.

Copy
#Create a data frame from the input variables
df <data.frame(cbind(Target, Trend, Season))
#Train model on all records with Target values
model <lm(Target ~ Trend + factor(Season),data=df[!is.na(Target), ])
#Return predictions from the model
Forecast <predict(model, newdata = df[, -1])
#Persist objects to file
save(list=c("df", "model", "Forecast"), file=paste(FileName,".Rdata", sep = ""))