Skip to content
Back to formatted view

Raw Message

Message-ID: <4A130C55.5010801@idi.ntnu.no>
Date: 2009-05-19T19:45:25Z
From: Wacek Kusnierczyk
Subject: exists function on list objects gives always a FALSE
In-Reply-To: <8b356f880905191226v5f849d26r17a5d01f77aa7fa3@mail.gmail.com>

Stavros Macrakis wrote:
>
> You might think that you can check names(xxx) to see if the slot has been
> explicitly set, but it depends on *how* you have explicitly set the slot to
> NULL:
>
>    > xxx$hello <- 3
>    > xxx$hello <- NULL
>    > names(xxx)
>    character(0)                  # no names -- assigning to NULL kills slot
>   

kills indeed:

    foo = list(bar=1)

    with(foo, bar)
    # 1

    foo$bar = NULL
    with(foo, bar)
    # error: object 'bar' not found

>    > xxx <- list(hello=NULL)
>    > names(xxx)
>    [1] "hello"                    # 1 name -- constructing with NULL-valued
> slot
>   

but:

    # cleanup -- don't do it in mission critical session
    rm(list=ls())

    foo
    # error: object 'foo' not found

    foo = NULL
    foo
    # NULL

that is, foo$bar = NULL kills bar within foo (even though NULL is a
valid component of lists), but foo = NULL does *not* kill foo.

> Welcome to R!
>   

... and its zemanticks.

vQ