R Action Blocks

Aus expecco Wiki (Version 2.x)
Wechseln zu: Navigation, Suche


With expecco18.1, another new block type is introduced: "R Actions". These behave similar to other script action blocks, in that they are defined by a script (in this case: R script language) and are placed into the test sequence flow just like any other block.

Similar to the plot/graph (gnuplot) actions, these may generate a graphic document (jpeg, png or postscript), which can be added to the activity log, or added as attachment. The graphic (and possibly other output data) will therefore be available in the generated "elf" execution log file, and/or shown in the generated "pdf" report file. Of course, you can do anything you like with the generated graphic file, by feeding the name of the generated file to another action for further processing.

Creating R Script Action Blocks

Script action blocks are created via the "Actions - More - R Action" menu item.

Select the "R Action" item, to create a new R action. An initial set of input pins and an initial (demo-) script is generated for you.

For details on the scripting language, please refer to the public R documentation for example, "https://www.r-project.org/" or the tutorial at "https://www.tutorialspoint.com/r/index.htm", or take a look at "https://en.wikipedia.org/wiki/R_(programming_language)".

Any input pin named "<pinName>" is available in the script as "%(pinName)". Thus, the script can be parametrized in arbitrary ways. A number of pins are already created for you (or can be added via the "Special Pins" menu item); these are:

  • "stdout"
    the standard output (if any) as generated by the script
  • "stderr"
    the standard error (if any) as generated by the script
  • "data"
    If connected, and a collection of values is present, these values will be written into a temporary data file, and the filename is available in the gnuplot script as "%(data)". This will be the raw data, to be processed by the script.
  • "dataSize"
    There is no pin for that, but the value is available to the script. It provides the number of data points (or rows) in the data file.

A Simple R Script (which also generates a Plot)

A typical R script looks like:

jpeg( "%(imageFile)" )
barplot(table(sample(1:3, size=1000, replace=TRUE, prob=c(.30,.60,.10))))

where "<imageFile>" is the name of an input pin, which provides the name of the jpeg file to be generated. This file can be attached to the log and/or report using a "Log [Image]" action,

Accessing Data from Attachments

You can directly access expecco attachment files by their name inside the script using the "%(Attachments)" macro; if you have an attachment with filename "foo.dat", use ... data "%(Attachments)/foo.dat" ... inside the script. Notice that the attchment's filename is to be used - not its name in the tree.


By default, there is no input stream given to R, so it will immediately read an EOF (end of file) and proceed or exit. If the script needs input (some examples from the internet need a "RETURN" prompt to finish), you should give the action a "stdin" input pin (via the "Special Pins" menu) and define the input there (most convenient as "Multiline String").

See Also

"Using_Gnuplot_Action_Blocks" these provide a similar functionality and are specially suited for graphs/plots.
" Script Execution in General" information on script execution in general (describes input/output, environments, argument passing etc.)

Copyright © 2014-2018 eXept Software AG