uses code to define a function in the R workspace and returns a reference (handle) to an R function defined in the R workspace, which also has the head RFunction.
represents a reference to an R function defined in the R workspace.
calls an R function represented by the RFunction object on arguments args.
- If the function has not been defined before in the current RLink session, RFunction[code] constructs a function defined by R code string code in the R workspace, and returns an opaque Wolfram Language reference to this function, having the longer form RFunction[type,RCode[code],refIndex,attributes]. If the code code does not define a valid R function, $Failed is returned.
- The longer form RFunction[type,RCode[code],refIndex,attributes] represents a FullForm of the R function handle, which is an opaque Wolfram Language reference to the function defined in the R workspace. Normally, this form is returned as a result of calling functions such as RFunction[code] or REvaluate[code], rather than constructed manually.
- The type parameter can be "closure" or "builtin". The former usually indicates that the R function in question is itself written in R language, while the latter means that it is one of the core R built-in functions.
- The type parameter in an RCode wrapper represents the code of the function. If the reference was created as a result of calling RFunction[code], then the code in RCode is exactly the code used to define this R function. If the reference was created as a result of calling REvaluate, the code inside RCode is a so-called deparsed (obtained by using the R deparse function) definition of an R function in question.
- The refIndex parameter can be a positive integer or Automatic. The former case corresponds to the references obtained via calls to REvaluate. The latter case corresponds to the references obtained via calls to RFunction[code].
- References with refIndex as an integer are generally only valid through a single RLink session. In contrast, references with refIndex set to Automatic are valid across Wolfram System or RLink sessions.
- The function's attributes attributes have the head RAttributes.
Examplesopen allclose all
Basic Examples (8)
This defines a higher-order function that takes a vector and another test function, and selects from the vector elements satisfying the criteria of test function (analog of the Wolfram Language's Select):
Neat Examples (1)
The following code will create a generator for closures that would perform some custom Select-like operations on a list that will be hard-coded into them. It will return a function that will embed some vector and will expect some test criteria to filter this vector. First, create a generator of closures: