r - How to convert list.files() output to an int? -
this question has answer here:
- how count number of files read list? 1 answer
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
Post a Comment