Skip to content
Back to formatted view

Raw Message

Message-ID: <4A12DEAB.3080701@idi.ntnu.no>
Date: 2009-05-19T16:30:35Z
From: Wacek Kusnierczyk
Subject: exists function on list objects gives always a FALSE
In-Reply-To: <4471fca90905190907j19203cb9wc01ae38de8415ab0@mail.gmail.com>

?rout?k wrote:
>
>> SmoothData <- list(exists=TRUE, span=0.001)
>> SmoothData
>>     
> $exists
> [1] TRUE
>
> $span
> [1] 0.001
>
>   
>> exists("SmoothData")
>>     
> TRUE
>
>   
>> exists("SmoothData$span")
>>     
> FALSE
>
>   

    'SmoothData$span' = 'foo'
    exists("SmoothData$span")
    # TRUE

>> exists("SmoothData[[2]]")
>>     

    'SmoothData[[2]]' = 'bar'
    exists("SmoothData[[2]]")
    # TRUE


the problem in your case is that you have an object named 'SmoothData'
with a nested component named 'span', but you're testing for the
existence of an object named 'SmoothData$span'. 

as shown in a recent post, one attempt to do your task would be

    exists('SmoothData') && 'span' %in% names(SmoothData)
    # TRUE

vQ