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[type,RCode[code],refIndex,attributes ] represents a reference to an R function defined in the R workspace.
RFunction[type,RCode[code],refIndex,attributes ][args] calls an R function represented by the 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.
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):