Nathaniel Smith wrote: > On Sun, Jul 5, 2009 at 2:04 AM, Laurent Gautier<lgaut...@gmail.com> wrote: >> (''' q <- function(...) { <whatever> } ''' is only adding a function q() >> in the globalenv; baseenv['q']() would still call the original function). > > Okay, append 'assign("q", q, envir=.BaseEnv)' to that line (if it > really matters; the goal would be to protect against mistakes, not > malice aforethought).
Well, well... in the GUI-with-R-console scenario, I would not completely let to chance what users would, or would not, do ;-) [one could write "base::q()" in that console, thinking that it would get rid of the R console but not anticipating that the whole application would disappear without leaving a chance to save work)] Also, the base environment is a so-called "locked environment": > assign("q", q, envir=as.environment("package:base")) Error in assign("q", q, envir = as.environment("package:base")) : cannot change value of locked binding for 'q' >> One of the use-cases for setting a cleanup function is for example if you >> are building an application and want to offer an R console, but want to >> prevent the user (or run python-level cleanup) from terminating the >> application from the console. > > Python-level cleanup makes sense. Ideally one would raise a > SystemExitException, but I guess it'd be hard to get the exception out > of the R callback and into the Python runtime. I have to do with what the R API is like, but the callback is a python function (just like the readconsole, writeconsole, etc...). Currently the way it goes/should go is like: 1- exiting is called from R (by q() for example) 2- the cleanup (callback) function is called (thati 3- depending on what the function returns it should 0 - do not save the workspace and leave 1 - save the workspace and leave None - abort the exit. In that case the embedded R appears to raise an R error with an empty message (which gets propagated back to Python as an RRuntimeError with an empty message when calling q()). The 0,1,None bit is mimicking the way it is currently working with R and it's win32/Aqua/JRI front-ends... L. > -- Nathaniel ------------------------------------------------------------------------------ _______________________________________________ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list