Passing code to R AE

Language Adapters for compiled languages like C++ and Fortran are designed as wrappers for the C API and do not allow custom code in the run time. The R language is different because each R snippet is interpreted rather than compiled when it is started as an Analytic Executable.

It is assumed that when you are using R, code is passed to the AE through environment variables as serialized and base-64 encoded plain text, or by pointing to a file that is saved in the file system. In some of these modes, the presence of serialized R objects is assumed, while in others the code is passed as is. Common to all modes is that the user input is passed as the last argument of the function or aggregate that is being started. This mechanism is called Dynamic Environment:
SELECT * FROM some_table, TABLE WITH FINAL(r_udtf(some_table.some_column,
'ABSOLUTE_PATH=/path/to/a/file.R'));
The available modes are:
ABSOLUTE_PATH
Points to any file available in the file system, with the referenced file that contains a serialized list with functions and data.
If this file is to be accessed from both Host and SPUs, then the best solution is to save it in the NFS share. Namely, the NFS share is pointed to by the environment variable $NZ_EXPORT_DIR $NZ_EXPORT_DIR/ae.
WORKSPACE_PATH
Points to a file of the same format, but located in the workspace directory, which by default is $NZ_EXPORT_DIR/ae/workspace/nz/r_ae.
PLAIN_PATH
Points to a file that contains R source code, including the same contents. In this case, the referenced file is not serialized.
CODE_SERIALIZED
Includes a serialized and base64-encoded list.
CODE_PLAIN
Provides code in plain-text; this mode is most suitable for embedding R code in SQL queries and stored procedures, but requires caution to ensure that the code is correctly escaped, as required by SQL and Dynamic Environment.