-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of cgenolin
Sent: Saturday, February 04, 2012 2:41 AM
To: r-help at r-project.org
Subject: [R] 'deparse(substitute'))' then 'assign' in a S4 methods
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())
}
[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:
+++++++++
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.