User Tools

Site Tools


Tips for writing the R script for JUICE-R

Even R beginners should be able to write simple R script for JUICE-R function. Here are some tips and tricks (what not to forget, what works and what doesn't etc.)

Interactive R session (R GUI) or batch?

To run R in interactive mode means to run Rgui.exe, which offers GUI interface and command line. Batch mode means that you send the file with the script to R.exe, and it will run silently at the background and quit after the algorithm is finished. Advantage of interactive mode is that you see the whole process of the calculation and afterwards you may keep working with data in R. Advantage of batch mode is mainly speed and user friendliness - if you are interested only in result, you don't need to spend time opening and closing R GUI. In JUICE, you can choose between both modes (Rgui.exe or R.exe). Note that batch basically doesn't offer interactivity, while R GUI does. However, this could be circumvented. For example, if the purpose of the script is to draw the figure in R Graphics device (X11), the script may look like this:

plot (1:10, pch = 1:10, col = 1:10)
if (!interactive ()) repeat if (dev.cur () == 1) break

The first line will open the R graphics window and draw the image. The second line will evaluate, if you are using interactive or batch mode (for batch, interactive () returns FALSE). In batch mode, it will run the loop with condition dev.cur () == 1, which becomes TRUE at the moment when you close the R graphics window. As a result, the plot will be drawn and it will stay opened until you manually close it. In interactive mode, this line will be ignored.

Some scripts cannot be run in batch mode. Indicate this by Rgui.exe tag in JUICE-R tag header (see How to write the R script for JUICE).

tips.txt · Last modified: 2015/12/15 14:00 (external edit)