Message-ID: <4A12DEFB.9010708@stats.uwo.ca>
Date: 2009-05-19T16:31:55Z
From: Duncan Murdoch
Subject: exists function on list objects gives always a FALSE
In-Reply-To: <4471fca90905190907j19203cb9wc01ae38de8415ab0@mail.gmail.com>
On 5/19/2009 12:07 PM, ?rout?k wrote:
> Dear R-users,
>
> in a minimal example exists() gives FALSE on an object which obviously does
> exist. How can I check on that list object anyway else, please?
>
>> SmoothData <- list(exists=TRUE, span=0.001)
>> SmoothData
> $exists
> [1] TRUE
>
> $span
> [1] 0.001
>
>> exists("SmoothData")
> TRUE
>
>> exists("SmoothData$span")
> FALSE
>
>> exists("SmoothData[[2]]")
> FALSE
>
> Thank you for any opinion regarding this topic.
There is no variable with name "SmoothData$span", there is an element of
SmoothData with name "span".
To test for that, the safest test is probably
"span" %in% names(SmoothData)
but a common convention is to use
is.null(SmoothData$span)
because NULL elements are rare in lists.
Duncan Murdoch