Please keep the thread on the list <I'll do so as this does not appear to contain anything that shouldn't>
On 1/13/10 5:29 PM, Nick Schurch wrote: > 2010/1/13 Laurent Gautier<lgaut...@gmail.com>: >> >> >> >> Why use "True" and "False" when Python has True and False ? >> >> Why define the function and assign it to an R variable name at each call ? > > This was an example only - the actual subroutine is rather complex and > so is the r function that is built. I have found that for complex sets > of R commands, assigning them to a function is the most reliable way > of being able to deal things and, of course, I want to be able to use > the function repeatedly within a subroutine (ideally). Combining R commands into an R function is fine, but that something that can be distinct from assigning a R object (here a function) to a symbol/name (here "filter <- "). For example in rpy2 (in rpy that the same with the NO_CONVERSION mode I think): >>> import rpy2.robjects as robjects >>> f = robjects.r("function(x) x^2") >>> tuple(f(4)) (16,) The function has for "Python name" "f", and is exposed a Python function-like object, but does not have an "R name". Now consider the following Python function: def g(x, want_f=True): if want_f: return f(x) else: None >> There is the remote possibility that there is caching involved, and r.filter >> is bound to your first function definition (and not rebound when >> redefined... since rpy is not told to do so). >> Anyway, what is shown can be seen as not-so-elegant; what about defining 2 >> functions filter_true, filter_false one for all call one or the other. Or >> even better, make named list element ("forenames" or "surnames" a parameter >> to *one* function) ? > > As I said, the actual subroutine is rather complex and currently does > define multiple functions for the different cases - but I'm up to 6 > different functions now and it really isn't an elegant solution. There > must be a way to force rpy to unbind a function. An elegant way would not involve overwriting the same global R variable over and over again, IMHO... especially if you have complex routines calling eachothers (and possibly overwriting each other's previously defined R functions). >> In R, one would delete the object going by the symbol "filter" from >> GlobalEnv: >> >> rm("filter") > > This doesn't seem to work from inside python though. > I might be mistaken, but I do not see why it wouldn't. How are you trying to achieve it (a standalone example one could copy/paste would demonstrate that it is not working). L. ------------------------------------------------------------------------------ This SF.Net email is sponsored by the Verizon Developer Community Take advantage of Verizon's best-in-class app development support A streamlined, 14 day to market process makes app distribution fast and easy Join now and get one step closer to millions of Verizon customers http://p.sf.net/sfu/verizon-dev2dev _______________________________________________ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list