void AddVarsFromR( Matrix mVarNames <, Matrix mVarLabels>, String sRExpr )
void AddVarsFromR( String sRExpr )
Matrix mVarNames
A vector that specifies the names to assign to the variables in the DataObject. Each string must be a valid SAS variable name.
Matrix mVarLabels
A vector that specifies the labels to assign to the variables in the DataObject. A variable's label describes the variable. The string mVarLabels[i] specifies the label of the variable whose name is mVarNames[i]. If the mVarLabels parameter is not specified, each variable is assigned a label that is the same as its name.
String sRExpr
An R expression that is evaluated and then coerced to a data frame. The number of variables (columns) in the data frame must match the number of entries in the vectors mVarNames and mVarLabels.
This method adds one or more variables to the DataObject using the result of evaluating an R expression. The method evaluates the R expression, coerces the result to an R data frame, and adds the variables of the data frame to the DataObject.
If you specify the parameter mVarNames, the names of the variables in the R data frame are ignored. If you do not specify the parameter mVarNames, the names of the variables in the R data frame are used when adding the variables to the DataObject. Because SAS has different variable naming rules from R, IMLPlus applies the following transformations to convert an R variable name to a valid SAS variable name:
For information about how IML Studio transfers data from R to IMLPlus, please refer to the topic Data Exchange Details.
DataName = "Baseball"; Xvar = "no_hits"; Yvar = "no_home"; declare DataObject dobj = DataObject.CreateFromFile( DataName ); dobj.ExportToR( "df" ); submit Xvar Yvar / R; fm <- lm( &Yvar ~ &Xvar, data=df ) endsubmit; dobj.AddVarsFromR( {"Fit", "Residual"}, "cbind( fitted(fm), residuals(fm) )" ); declare ScatterPlot plot; plot = ScatterPlot.Create( dobj, Xvar, Yvar ); dobj.GetVarData( Xvar, x ); dobj.GetVarData( "Fit", fit ); plot.DrawUseDataCoordinates(); plot.DrawSetPenColor( RED ); plot.DrawLine( x, fit ); plot = ScatterPlot.Create( dobj, "Fit", "Residual" ); plot.DrawUseDataCoordinates(); plot.DrawSetPenAttributes( BLUE, DASHED, 1 ); plot.DrawLine( 0, 0, 30, 0 ); plot.SetWindowPosition( 50, 50 );
DataObject.AddAnalysisVarFromR
DataObject.AddAnalysisVarsFromR
DataObject.AddVarFromR