Something in new() or validObject() in the methods package is messing
up. This happens in both 2.1.0 and R-devel in Windows.
I'd like to have an empty expression for a slot in a class. An empty
expression is an expression:
> is.expression(expression())
[1] TRUE
>
> is(expression(), "expression")
[1] TRUE
> class(expression())
[1] "expression"
However, when I try to use this as the initial value, I get an error
thrown back at me:
> setClass("foo", representation(bar = "expression"))
[1] "foo"
>
> new("foo", bar = expression())
Error in validObject(.Object) : invalid class "foo" object: invalid
object for slot "bar" in class "foo": got class "NULL", should be or
extend class "expression"
Is it doing an extra eval or something? It looks like it:
> x <- expression()
> x
expression()
> eval(x)
NULL
>
> x <- quote(expression())
> x
expression()
> eval(x)
expression()
> eval(eval(x))
NULL
However, it doesn't always happen:
> new("foo", bar = expression(1+1))
An object of class "foo"
Slot "bar":
expression(1 + 1)
> x <- expression(1+1)
> x
expression(1 + 1)
> eval(x)
[1] 2
Duncan Murdoch
Bug in new() or validObject() in methods package (PR#7922)
3 messages · Duncan Murdoch, Peter Dalgaard
murdoch@stats.uwo.ca writes:
Is it doing an extra eval or something? It looks like it:
> x <- expression() > x
expression()
> eval(x)
NULL
> > x <- quote(expression()) > x
expression()
> eval(x)
expression()
> eval(eval(x))
NULL
You do realize that the two expression() results are not identical:
x <- quote(expression()) class(x)
[1] "call"
x <- expression() class(x)
[1] "expression" Not that I can fathom what bearing that has on the real problem...
O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907
On 6/6/2005 4:55 PM, Peter Dalgaard wrote:
murdoch@stats.uwo.ca writes:
Is it doing an extra eval or something? It looks like it:
> x <- expression() > x
expression()
> eval(x)
NULL
> > x <- quote(expression()) > x
expression()
> eval(x)
expression()
> eval(eval(x))
NULL
You do realize that the two expression() results are not identical:
x <- quote(expression()) class(x)
[1] "call"
x <- expression() class(x)
[1] "expression" Not that I can fathom what bearing that has on the real problem...
I figured they weren't identical, given that they gave different results when eval'd, but I didn't know what the difference was exactly. Thanks! Duncan