r - How to convert list.files() output to an int? -


this question has answer here:

the output when checking empty directory r's list.files() character string...

> list.files('/home/somedir') character(0) 

but test length , use in control structure like

> current <- '/home/somedir' > dirpick <- function(){     trycatch(       if (length(list.files(current) > 0)) {         dirdata <- current       } else {         dirdata <- old       }     )   } 

but object returned list.files() doesn't act i'd expect:

> list.files('/home/somedir') == 0 logical(0)   > as.numeric(list.files('/home/somedir')) == 0 logical(0) 

not sure understand difference between logical , boolean, why doesn't act integer zero?

try:

length(list.files('/home/somedir')) == 0 

the value character(0) indicates empty variable. thats why can't sum or convert 0 without length() attribute


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -