Building the script template
The script template specifies the R script or Python for Spark script that the custom node dialog will generate. A single custom node dialog can be used to specify one or more operations which will run in sequence.
The script template might consist of static text. Static text is different to the static text control; it is R code or Python for Spark code that is always generated when the node runs. For example, command names and subcommand specifications that don't depend on user input are static text. The script template might also consist of control identifiers that are replaced at run-time with the values of the associated custom node dialog controls. For example, the set of fields specified in a field chooser is represented with the control identifier for the field chooser control.
To build the Script Template
- For static text that does not depend on user-specified values, enter the R script or Python for Spark script as you would in, for example, the R model building syntax field of the R Build node.
- Add control identifiers of the form
%%Identifier%%
at the locations where you want to insert R script or Python for Spark script generated by controls, whereIdentifier
is the value of the Identifier property for the control.- You can insert a control identifier by selecting a row in the table of identifiers, right-clicking and selecting Add to script template. You can also insert a control identifier by right-clicking a control on the canvas and selecting Add to script template.
- You can also select from a list of available control identifiers by pressing Ctrl+Spacebar. The list contains the control identifiers followed by the items available with the script auto-completion feature.
At run-time, and for all controls other than check boxes, check box groups, and the static text control, each identifier is replaced with the current value of the Script property of the associated control. If the control is empty at run-time, it does not generate any script. For check boxes and check box groups, the identifier is replaced by the current value of the Checked R Script or Unchecked R Script property of the associated control, depending on the current state of the control--checked or unchecked. See the topic Control types for more information.
Example: Including run-time values in an R script template
In this example, the custom node dialog will generate and run R script to build and score a
linear regression model, using a call to the R lm
function with the signature shown
here.
lm(formula,data)
formula
specifies an expression, such asNa~Age
, whereNa
is the target field of the model, and the input field of the model isAge
.data
is a data frame containing the values of the fields that are specified in the formula.
Consider a custom node dialog with a single field chooser control that allows the user to choose the input field of the linear model. The script template to generate and run the R script that builds the model is entered on the Script tab, and might look like this:
modelerModel <- lm(Na~%%input%%,data=modelerData)
%%input%%
is the value of the Identifier property for the field chooser control. At run-time it will be replaced by the current value of the Script property of the control.- Defining the Script property of the field chooser control to be
%%ThisValue%%
specifies that at run-time the current value of the property will be the value of the control, which is the field that is chosen from the field chooser.
Suppose the user of the custom node dialog selects the Age field as the input field of the model. The following R script is then generated by the node dialog:
modelerModel <- lm(Na~Age,data=modelerData)
The script template to generate and run the R script that scores the model is entered on the Score Script tab, and might look like this:
result <- predict(modelerModel,newdata=modelerData)
var1 <-c(fieldName="predicted", fieldLabel="",fieldStorage="real",fieldMeasure="",fieldFormat="",
fieldRole="")
modelerDataModel<-data.frame(modelerDataModel,var1)
This R script does not depend on any user-specified values, only on the model that is built using the model building R script. Therefore, the model scoring R script is entered as it would be in the R model scoring syntax field of the R Build node.