Topics: |
An RScript can run plots, charts, summaries, model techniques, or even be used to generate 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.
Topics: |
How to: |
To run the RScript, note the following:
The following example shows an RScript that is run to create a plot.
Note: Once the RScript button is active (selected), you can upload an RScript. When you select this option, only files with an extension of .R appear as an available file type. The files that appear in the Filename list are contextual, and depend on the Source you select (for example, FEX, CSV File, or Rscript). An example of this is shown in the following image.
How to: |
Reference: |
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 and higher, 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, running 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 run the following code lines with RStat open:
cat(pmmltoc(toString("dec tree.xml") , "dec tree", TRUE, "", FALSE), file = "dec tree.c")
WebFOCUS | |
Feedback |