OpenMS  2.7.0
Static Public Member Functions | List of all members
RWrapper Class Reference

R-Wrapper Class. More...

#include <OpenMS/SYSTEM/RWrapper.h>

Static Public Member Functions

static String findScript (const String &script_file, bool verbose=true)
 Look for an R script in the share/OpenMS/SCRIPT folder. More...
 
static bool findR (const QString &executable=QString("Rscript"), bool verbose=true)
 Check for presence of 'Rscript'. More...
 
static bool runScript (const String &script_file, const QStringList &cmd_args, const QString &executable=QString("Rscript"), bool find_R=false, bool verbose=true)
 Run an R script with certain arguments on the command line. More...
 

Detailed Description

R-Wrapper Class.

Call R scripts from OpenMS, mainly to produce plots.

Member Function Documentation

◆ findR()

static bool findR ( const QString &  executable = QString("Rscript"),
bool  verbose = true 
)
static

Check for presence of 'Rscript'.

Parameters
verbosePrint failure information?
Returns
Success status

◆ findScript()

static String findScript ( const String script_file,
bool  verbose = true 
)
static

Look for an R script in the share/OpenMS/SCRIPT folder.

The script filename can be an absolute filename (in which case the filename is returned unchanged), or a relative filename or just a filename. In the latter cases, the script will be searched in the OpenMS 'SCRIPTS' path (share/OpenMS/SCRIPTS) and the full filename will be returned.

An exception will be thrown if the file cannot be found.

Parameters
script_fileName of the R script
verbosePrint error message to OPENMS_LOG_ERROR upon FileNotFound
Returns
Full filename with absolute path
Exceptions
Exception::FileNotFound

◆ runScript()

static bool runScript ( const String script_file,
const QStringList &  cmd_args,
const QString &  executable = QString("Rscript"),
bool  find_R = false,
bool  verbose = true 
)
static

Run an R script with certain arguments on the command line.

The following checks are done before running the script: 1) [optional] 'Rscript' executable is searched (see findR() – set find_R to true) 2) The script_file is searched in 'OpenMS/share/SCRIPTS' (see findScript()). 3) The script is run as $ Rscript <path/to/script> <arg1> <arg2> ...

If any of the above steps fail, an error message is printed and false is returned.

The 'cmd_args' are passed via commandline and should be read by the R script using R' commandArgs() function. Usually, the args are input and output filenames.

Parameters
script_fileFilename of the R script
cmd_argsCommand line arguments to the script
find_RRun findR()? May be skipped if runScript() is run repeatedly
verbosePrint status information; also passed internally to findR() and findScript().
Returns
Success status