@KFStep(name="RScriptExecutor", category="Scripting", toolTipText="A Knowledge Flow component that executes a user-supplied R script. The script may be supplied via the GUI editor for the component or loaded from a file at run time. Incoming instances will be transfered to a data frame in the R environment and can be accessed from the user script by referencing the variable \"rdata\". Console output in R can be forwarded to a TextViewer by using \"print\" statements in R. E.g. \n\ndata(iris)\nprint(iris)\n\nData frames in R can be extracted, converted to Weka Instances and passed on via dataSet connections by simply stating the name of the data frame in the user\'s R script. This *must* be the last command in the script. E.g:\n\ndata(iris)\niris\n\nGraphics in R can be captured by making use of the JavaGD graphics device for R (http://stats.math.uni-augsburg.de/R/JavaGD/). The Weka RPlugin will attempt to install this package for the user automatically - if this fails for some reason then the package should be installed by the user from R via install.packages(\"JavaGD\"). The default size for graphics created in R via JavaGD is 800x600. The user can alter this in their R scripts by executing the following command:\n\nJavaGD(width=w, height=h)\n\nwhere \"w\" and \"h\" are the new width and height in pixels. Note that this setting stays in effect until another \"JavaGD()\" command is executed.\n\nThe RScriptExecutor can be connected to an ImageSaver component in order to save any graphics generated to a file. If running within the graphical Knowledge Flow UI any generated images will also be sent to the R Console/Visualize perspective.", iconPath="weka/gui/knowledgeflow/icons/RScriptExecutor.gif") public class RScriptExecutor extends BaseStep implements JavaGDListener
data(iris) print(iris)
Data frames in R can be extracted, converted to Weka Instances and passed on via dataSet connections by simply stating the name of the data frame in the user's R script. This must be the last command in the script. E.g:
data(iris) iris
Graphics in R can be captured by making use of the JavaGD graphics device for R (http://stats.math.uni-augsburg.de/R/JavaGD/). The Weka RPlugin will attempt to install this package for the user automatically - if this fails for some reason then the package should be installed by the user from R via install.packages("JavaGD"). The default size for graphics created in R via JavaGD is 800x600. The user can alter this in their R scripts by executing the following command:
JavaGD(width = w, height = h)
where "w" and "h" are the new width and height in pixels. Note that this setting stays in effect until another "JavaGD()" command is executed.
The RScriptExecutor can be connected to an ImageSaver component in order to save any graphics generated to a file. If running within the graphical Knowledge Flow UI any generated images will also be sent to the R Console/Visualize perspective.Constructor and Description |
---|
RScriptExecutor() |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getCustomEditorForStep() |
java.util.List<java.lang.String> |
getIncomingConnectionTypes() |
java.util.List<java.lang.String> |
getOutgoingConnectionTypes() |
java.lang.String |
getRScript()
Get the script to execute
|
java.io.File |
getScriptFile()
Get the filename of the script to load at runtime
|
void |
imageGenerated(java.awt.image.BufferedImage image)
Called when a graphics image has been generated
|
void |
processIncoming(Data data) |
void |
setRScript(java.lang.String script)
Set the script to execute
|
void |
setScriptFile(java.io.File scriptFile)
Set the filename containing the script to be loaded at runtime
|
void |
start() |
void |
stepInit() |
environmentSubstitute, getDefaultSettings, getInteractiveViewers, getInteractiveViewersImpls, getName, getStepManager, globalInfo, isResourceIntensive, isStopRequested, outputStructureForConnectionType, setName, setStepIsResourceIntensive, setStepManager, setStepMustRunSingleThreaded, stepMustRunSingleThreaded, stop
@ProgrammaticProperty public void setRScript(java.lang.String script)
script
- the R script to executepublic java.lang.String getRScript()
@OptionMetadata(displayName="File to load script from", description="A file to load the R script from (if set takes precedenceover any script from the editor", displayOrder=1) @FilePropertyMetadata(fileChooserDialogType=0, directoriesOnly=false) public void setScriptFile(java.io.File scriptFile)
scriptFile
- the name of the script file to load at runtimepublic java.io.File getScriptFile()
public void stepInit() throws WekaException
stepInit
in interface BaseStepExtender
stepInit
in interface Step
WekaException
public void start() throws WekaException
start
in interface BaseStepExtender
start
in interface Step
start
in class BaseStep
WekaException
public void processIncoming(Data data) throws WekaException
processIncoming
in interface BaseStepExtender
processIncoming
in interface Step
processIncoming
in class BaseStep
WekaException
public java.util.List<java.lang.String> getIncomingConnectionTypes()
getIncomingConnectionTypes
in interface BaseStepExtender
getIncomingConnectionTypes
in interface Step
public java.util.List<java.lang.String> getOutgoingConnectionTypes()
getOutgoingConnectionTypes
in interface BaseStepExtender
getOutgoingConnectionTypes
in interface Step
public void imageGenerated(java.awt.image.BufferedImage image)
JavaGDListener
imageGenerated
in interface JavaGDListener
image
- the image generatedpublic java.lang.String getCustomEditorForStep()
getCustomEditorForStep
in interface Step
getCustomEditorForStep
in class BaseStep