[Rd] throwing a "condition" when the current working directory changes

Romain Francois romain.francois at dbmail.com
Fri Mar 20 23:05:08 CET 2009


Hi,

Would it make sense to throw a condition when the working directory 
changes, so that interested parties (such as guis can act based on the 
change using an appropriate calling handler), and not interested parties 
can just ignore it.

For example, something like this:

setwd <- function (dir) {
       out <- .Internal(setwd(dir))
       setwdCondition <- simpleCondition( paste( "setwd: ", dir)  )
       class( setwdCondition ) <- c("setwd", "condition" )
       setwdCondition$dir <- dir
       signalCondition( setwdCondition )
       invisible( out )
}

which could handled like this to have your prompt responding to changes 
of current directory:

withCallingHandlers( f()  , setwd = function(e) options( prompt = 
sprintf( "[%s]> ", e$dir )  )   )

Beyond the simple example, would it make sense to define a set of 
condition or events, or is this abusing the concept of conditions and 
something else should be used ? hooks ?

Also, is there a way to "register" a calling handler so that it listens 
to every top-level command. Something like options( "error") but for 
handling other kinds of conditions ?

Romain

-- 
Romain Francois
Independent R Consultant
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr



More information about the R-devel mailing list