Romain Francois
2009-Mar-20 22:05 UTC
[Rd] throwing a "condition" when the current working directory changes
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