R integration functions
The R expressions let you enhance expression calculations using R functionality. You can access R functionality through two expression functions: RCall and RScript. You can find these functions in the Modelling Functions folder in the expression editor.
Note
The ModelScore expression function is also used in relation to R models — see Scoring records using an R model.
Note
To use the R expressions, you must first set up the R integration for FastStats.
RCall¶
This function allows you to call out to an R function with data from your FastStats system.
This calls a function named functionName in R with a vector of numbers c(number1, number2, ...).
Parameters¶
The first parameter (text) is the name of the function you want to call.
The remaining parameters (numeric) are numbers that you want to pass as arguments to the function call.
Examples¶
Access functionality not implemented in FastStats expressions — calculate the 0.975 quantile of the standard normal distribution (=1.96):
Pass a vector of values to the R function — can include variables and calculated values:
Note
If the function is not loaded automatically at the start of an R session and needs a library() call to make it available (for example, if it's from a third-party CRAN package), you will need to use RScript and include the library() call as an additional command before the function call itself. See the R integration for FastStats documentation for information on changing the default packages available on start-up.
RScript¶
This function allows you to call out to a number of R functions with data from your FastStats system, using an R script.
This runs script in R. @1, @2, etc. are substituted by number1, number2, etc. when the script is run.
Parameters¶
The first parameter (text) is the script you wish to run.
The remaining parameters (numeric) are numbers you wish to substitute into the placeholder values @1, @2, etc. in the script.
Examples¶
Call a single function using RScript to specify optional parameters — calculate the 0.9 quantile of a normal distribution with mean 80 and standard deviation 5 (=86.4078):
Use multiple R commands:
RScript("x<-mean(@1,@2);y<-median(@1,@2,@3,@4);min(x,y)", [Pie sales], [Cake sales], [Nut sales], [Cheese sales])`
Note
As with normal text expressions, the script parameter for RScript is limited to 32767 characters in length.
Note
There are some security-related restrictions on what the script can do. For example, you cannot run an executable or access the computer's filesystem.