Friday, July 8, 2011

RattleR

Rattle is a useful data analysis UI for R.

Unfortunately, it's a bit hard to get started from a shortcut such as an XDG .desktop file. The usual method (ala Rkward and RCommander), `R_DEFAULT_PACKAGES="$R_DEFAULT_PACKAGES rattle" R`, doesn't work. Instead, one is left doing the `library(rattle); rattle()` commands in an R terminal.

A first stab with Rscript fails:


#!/usr/bin/env Rscript
library(rattle)
rattle()

This starts Rattle, then exits both Rattle and R. Obviously, rattle() is spawning a thread and returning immediately, causing RScript to reach EOF and exit. The same happens when the commands are sent to R, r, or Rscript via STDIN.

Adding a line to wait for an enter keypress seems a likely workaround:


#!/usr/bin/env Rscript
library(rattle)
rattle()

system('bash -c read')

This starts Rattle, and pauses R waiting for an enter key as expected, but Rattle does not receive input. Whatever it's doing for its UI, it is not properly threaded as locking up the parent also locks up the child --- probably some sort of "greenthreads" ala Ruby or Python.

It turns out, however, that this is not an unknown problem. A query of "R_DEFAULT_PACKAGES rattle" turns up pages that provide a fix for the original method: specifying Rattle's dependencies.

The correct command is therefore

 R_DEFAULT_PACKAGES="datasets,utils,grDevices,graphics,stats,rattle" R -q --save

Note the -q, to suppress the startup text, and --save (or, alternately, --no-save) to suppress the confirm-quit message. This should be launched in a .desktop file with Terminal=true. R will still wait around for a q() or Ctrl-D, but that is a small price to pay.




No comments:

Post a Comment