[R] 'deparse(substitute'))' then 'assign' in a S4 methods
cgenolin
cgenolin at u-paris10.fr
Sat Feb 4 11:41:14 CET 2012
Hi the list,
I am writing a function in which I need to affect a variable on a higher
level. My fnction could be:
++++++++++++++++++
fooBis <- function(x){
nameObject <- deparse(substitute(x))
print(nameObject)
assign(nameObject,4,envir=parent.frame())
}
> fooBis(e)
[1] "e"
> e
[1] 4
-----------------
(to simplify, this fnction can affect only the number 4. But it does it in
the parent frame).
My problem is that I use S4 programming. So the code becomes:
+++++++++++++
setGeneric("foo",function(x){standardGeneric("foo")})
setMethod("foo","ANY",
function(x){
nameObject <- deparse(substitute(x))
print(nameObject)
assign(nameObject,4,envir=parent.frame())
}
)
-----------
But it does not work since the definition of foo is now:
+++++++++
> foo
nonstandardGenericFunction for "foo" defined from package ".GlobalEnv"
function (x)
{
standardGeneric("foo")
}
<environment: 0x125b7c0c>
-----------------
So how can I solve this problem? Is it possible to assign a value to a
variable on the upper level using S4?
Sincerely
Christophe
--
View this message in context: http://r.789695.n4.nabble.com/deparse-substitute-then-assign-in-a-S4-methods-tp4356748p4356748.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list