Creating the Syntax Template

The syntax template specifies the command syntax to be generated by the custom dialog. It contains control identifiers that are replaced at run-time with the values of the associated custom dialog controls.

The completed template is as follows:

BEGIN PROGRAM R. 

depvar="%%Variable%%" 
catvar="%%catvar%%" 
horizontal=%%orientation%% 
main="%%title%%" 
col=c(%%col%%) 
dta<-spssdata.GetDataFromSPSS(c(depvar,catvar))
catlbl=catvar
scalbl=depvar 
if (horizontal) { 
   temp=catlbl 
   catlbl=scalbl 
   scalbl=temp
}  

boxplot(as.formula(paste(depvar, "~", catvar)), data=dta, 
        xlab=catlbl, ylab=scalbl, main=main, horizontal=horizontal,
        col=col) 

END PROGRAM.
  • The BEGIN PROGRAM R-END PROGRAM block wraps the R code that sets up the arguments for the R boxplot function and calls the function.

  • Items enclosed in pairs of percent signs are control identifiers that tie controls from the dialog to the syntax template. For example, %%catvar%% specifies the dialog control that has catvar for the value of its Identifier property. At run time, the control identifiers in the syntax template will be replaced with the syntax generated by the associated controls. In this example, the identifier %%catvar%% will be replaced with the name of the variable in the Category axis control.

  • The function spssdata.GetDataFromSPSS, provided with the IBM® SPSS® Statistics - Integration Plug-in for R, reads data from the active dataset. In this example, it is used to read the data for the dependent variable depvar and the grouping variable catvar.

This tutorial is designed so you can copy the syntax shown here and paste it into the edit window in the Syntax Template pane of your custom dialog. When creating your own syntax templates, you can insert a control identifier into the template by selecting the control on the canvas, right-clicking and selecting Add to syntax template.

As an example of how the syntax template works, let's suppose the user makes the following choices in the dialog:

  • Moves a variable named mpg to the Variable control.
  • Moves a variable named cylinder to the Category axis control.
  • Keeps the default value of "blue" for the Box colors control.
  • Enters the value Miles per Gallon by Number of Cylinders for the Title control.
  • Leaves the Horizontal orientation box unselected.

The syntax generated by the dialog is as shown here.

BEGIN PROGRAM R.
 
depvar="mpg" 
catvar="cylinder" 
horizontal=FALSE 
main="Miles per Gallon by Number of Cylinders" 
col=c("blue") 
dta <-spssdata.GetDataFromSPSS(c(depvar,catvar)) 
catlbl=catvar
scalbl=depvar 
if (horizontal) { 
   temp=catlbl 
   catlbl=scalbl 
   scalbl=temp
}
 
boxplot(as.formula(paste(depvar, "~", catvar)), data=dta, 
        xlab=catlbl, ylab=scalbl, main=main, horizontal=horizontal, 
        col=col)
 
END PROGRAM.

Next