Re: [R] Turning control back over to the terminal

From: Martin Morgan <>
Date: Wed 15 Feb 2006 - 04:23:58 EST

Hi Ross --

Not a direct answer to your question, but here's an idea.

I guess you've got some script in a file

#! /bin/bash
R --no-save --no-restore --gui=none > `hostname` 2>&1 <<BYE
# some mpi commands
# other mpi commands

BYE and you do something like

mpiexec -np 10

Instead, you might create a file script.R



variousCmds <- function() {
  ## some mpi commands

  if( mpi.comm.rank() == 0 && interactive()) {
    while( (res <- readline( prompt=" > ")) != "DONE" ) {
      try(cat(eval(parse(text=res)), "\n"))
      ## or other, e.g., browser()

  ## other mpi commands

mpi.bcast.Robj2slave( variousCmds )
mpi.bcast.cmd( variousCmds())


Then just run R and


to debug, and

R --vanilla < script.R

to run. This assumes that the 'some' and 'other' mpi commands include communication of results between nodes, so that you don't have to rely on the the return value of variousCmds to harvest the results. This could be great fun, because you can edit the script file (in emacs, for e.g.) and rerun without exiting R. provided some inspiration for this, thanks!


Ross Boylan <> writes:

> I'm invoking R from withing a shell script like this
> R --no-save --no-restore --gui=none > `hostname`  2>&1 <<BYE
> # various commands here
> I would like to regain control from the invoking terminal at some point.
> I tried source(stdin()) but got a syntax error, presumably stdin is the
> little shell here snippet (the part between <<BYE
> and BYE).
> Is there some way to accomplish this?  I am trying to regain control
> inside an R session that has been launched inside an MPI environment
> (and I'm usually running inside emacs).  This is on a Mac OS X cluster.
> I suppose there might be a way to do this with expect, but I'm hoping
> for something simpler.  Potentially, I could make the script itself act
> differently on the head node (the only one I want to debug right now),
> including changing the redirection there.
> -- 
> Ross Boylan                                      wk:  (415) 514-8146
> 185 Berry St #5700                     
> Dept of Epidemiology and Biostatistics           fax: (415) 514-8150
> University of California, San Francisco
> San Francisco, CA 94107-1739                     hm:  (415) 550-1062
> ______________________________________________
> mailing list
> PLEASE do read the posting guide!

______________________________________________ mailing list PLEASE do read the posting guide! Received on Wed Feb 15 04:45:43 2006

This archive was generated by hypermail 2.1.8 : Wed 15 Feb 2006 - 15:28:29 EST