exists function on list objects gives always a FALSE
?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
This checks for existance of an object called "SmoothData$span", as in :
`SmoothData$span` <- 1:10
exists("SmoothData$span")
You can do:
is.list( SmoothData ) && !is.null(names(SmoothData)) && "span" %in%
names(SmoothData)
exists("SmoothData[[2]]")
FALSE
Similarly:
`SmoothData[[2]]` <- 1
exists("SmoothData[[2]]")
You can do:
is.list( SmoothData ) && length(SmoothData) > 1
Thank you for any opinion regarding this topic. Zroutik
Romain Francois Independent R Consultant +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr