In this section:
An RScript can run plots, charts, summaries, model techniques, or even be used to execute scoring functionality using R. As of RStat 1.3.1, RScripts can run using RStat, and depending on the technique, the RScript, if used to create a scoring routine, can be converted to a C routine like a native RStat scoring technique. For both capabilities, the package referenced by the RScript needs to be loaded to the RStat environment in the R workspace. Without the R package, the script will not run. If the intent of the RScript is to create a model and output a C file for the scoring routine to be used by the WebFOCUS Reporting Server, then the feature requires a few naming conventions and a few other items to be existent.
In this section:
To run the RScript, note the following:
The following example shows an RScript that is executed to create a plot.
Note: Once the RScript button is active (selected), the user can upload an RScript. When a non-script file is selected (for example, a .csv file or a .txt file), a message appears, as shown in the following image. The error message will also be shown in the RStat status bar and log file. The RScript button is looking for a R code file with an extension of .R.
To create the Scoring Routine C file from an RScript, note the following:
If you choose not to load the data set in RStat but want to export a C routine, you can load an .RData file or use a saved pmml/XML file to export the C routine in the R console with RStat opened. RStat will check crs$dataset before exporting any file. Thus, non-data exporting only can be done in the R console with an RStat session opened.
The .RData file saves the model summary as an R workspace. The example below shows related codes for the decision tree.
decTree<-rpart(PRICE_1991~.,dataset) save( decTree, file = 'wine_training_rpart.rdata')
The two code lines above should be included in the user script.
The following code will be the script uploaded by the RScript button in RStat 1.4, which first loads the .RData file to pass the model summary to crs$rpart, and then further defines the 'pmml.cmd' command.
load('wine_training_rpart.rdata') crs$rpart<-decTree pmml.cmd <- "pmml(crs$rpart)"
In the R console, executing the following code will export the C routine:
con <- file(dec tree.c", open="w") cat(pmmltoc(toString(eval(parse(text=pmml.cmd))), name="dec tree", includePMML=TRUE, includeMetaData="", exportClass=FALSE), file=con) close(con)
If you generate a pmml\XML file and want to export a C routine, you need to execute the following code lines with RStat open:
cat(pmmltoc(toString("dec tree.xml") , "dec tree", TRUE, "", FALSE), file = "dec tree.c")