The output when checking an empty directory with R's list.files()
is a character string...
> list.files('/home/someDir')
character(0)
But I would like to test its length and use it in a control structure like
> current <- '/home/someDir'
> dirPick <- function(){
tryCatch(
if (length(list.files(current) > 0)) {
dirData <- current
} else {
dirData <- old
}
)
}
But the object returned by list.files()
doesn't act like I'd expect:
> list.files('/home/someDir') == 0
logical(0)
> as.numeric(list.files('/home/someDir')) == 0
logical(0)
Not sure I understand the difference between a logical and boolean, but why doesn't this just act like an integer zero?