[TxMt] For all R users: a R daemon running 'inside' of TM (first trial)

Hans-Jörg Bibiko bibiko at eva.mpg.de
Thu Dec 6 10:38:43 UTC 2007


Hi,

here comes a suggestion for all R users.
I wrote a tiny R daemon bundle in order to run R 'inside' of TM.  
There is no need to start RGUI etc.
I found a naive way to do it and it turns out, at least for me, it's  
quite useful. So my question is whether this approach is also useful  
for others. If yes, I/we can elaborte this bundle.

Demo Movie (4.3MB) http://www.bibiko.de/Rsession.mov

Up to now you can do the following:

-install this bundle R daemon
-open new document, set the language to R or R console, type 'start'  
and press TAB
-R daemon will be installed into $HOME/Rdaemon (please check the  
directory if you don't use it!)
-after some seconds you can type any command into that window and  
press 'NUMPAD-ENTER'
-the result will be inserted into the current document
-if you want to execute a selection the output will be written into  
the file r_res (useful if you write a script)
-errors/warnings will be output as tooltip (but not every error, then  
you have to check 'geterrmessage()'!)
-there is a progress bar showing the progress of R's calculation

-the entire session you can find in r_out (the nice side-effect is  
that even if the R daemon, or TM, or the Mac crashes you have at  
least r_out to reconstruct the last session)
-the R daemon listens at the named pipe r_in
-errors/warnings are written to r_err

-if you know that the command will take some minutes you can execute  
this command in the background (SHIFT+NUMPAD-ENTER); the result will  
be written into r_res; by doing so you can send a task to R while  
writing further stuff in TM (I used sink() for that)

-R daemon comes with its own persistant history list (i.e. if you  
quit the R daemon and you start it again you also have all commands  
from the last session (OPT+ARROWUP/DOWN CTRL+OPT+ARROWUP for a list  
[last command comes first]))

-I rewrote the help for the current word as an HTML page using frames

-Autocomplete and command template now works case-sensitive meaning  
if you look for 'mat' you won't get 'Math.'. Furthermore it also  
works for functions defined in the current session!

-I included an example TM project Rsession ($HOME/Rdaemon).

-note 1: plot
R runs as normal session in a hidden Terminal. Thus one has to use  
X11 for plotting into the null device.
If such a device is open and you quit X11 the R daemon will quit  
immediately!! I cannot catch this yet.

CTRL+NUMPAD-ENTER can show the current plot as PDF. I set the the pdf  
file to ~/Rdaemon/plots/Rplot.pdf

-note 2: quit
You can type 'q()', delete the prompt and answer the question, or  
type kill TAB to kill it.

-known pitfall 1: readline
In principal readline("prompt") works, but if 'prompt' is prompted,  
you have to delete it or press ENTER to insert a value. Otherwise R  
will get the entire line a input (I work on it)

-known pitfall 2: synchronisation
One tricky point is the synchronisation of the output. I went the way  
to look for R's CPU coverage. If this is zero I assume that R's  
ready. One can test this if you execute 'c(1:200000)'. If you see the  
last line mentioning  you reached the max line etc. everything is OK,  
if not one has to fine-tune it. It's done via a tiny sleep command.

As I already mentioned this is written very fast!! Esp. the daemon  
which is written in Ruby needs some help from Ruby experts ;)

With R daemon one has the full control meaning you can do thousand of  
nifty things ;)

Any comments?

Cheers,

--Hans
-------------- next part --------------
A non-text attachment was scrubbed...
Name: R daemon.tmbundle.zip
Type: application/zip
Size: 32635 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20071206/c338021d/attachment.zip>


More information about the textmate mailing list