Class RScriptExecutor


  • public class RScriptExecutor
    extends Object
    The RScriptExecutor provides an interface for invoking R scripts via system commands. This provides a simple alternative to using rJava, which relies on JNI bits. The interface supports passing and retrieving values in a tabular format, as well as arbitrary arguments. The values are sent and retrieved from the script via stdin/stdout. The arguments are baked into the script using Freemarker tags.
    Author:
    jwhite
    • Field Detail

      • RSCRIPT_BINARY

        public static final String RSCRIPT_BINARY
        The Rscript binary used to execute the .R scripts.
      • SCRIPT_TIMEOUT_MS

        public static final long SCRIPT_TIMEOUT_MS
        Maximum runtime of the Rscript process in milliseconds before failing and throwing an exception.
        See Also:
        Constant Field Values
    • Constructor Detail

      • RScriptExecutor

        public RScriptExecutor()
    • Method Detail

      • exec

        public RScriptOutput exec​(String script,
                                  RScriptInput input)
                           throws RScriptException
        Executes by given script by: - Searching both the classpath and the filesystem for the path - Copying the script at the given path to a temporary file and performing variable substitution with the arguments using Freemarker. - Invoking the script with commons-exec - Converting the input table to CSV and passing this to the process via stdin - Parsing stdout, expecting CSV output, and converting this to an immutable table
        Throws:
        RScriptException