Reputation: 111
My script currently checks a folder called 'current', that always has data in it, the folder I'm trying to conditionally check is called 'future' and it only periodically has anything. The exact same script (other than destination folders) is the same for both current and future.
My experience with R is limited, but I have tried various combos of if/else and experimented with list.files, but I'm not having much luck. I also tried copying the script and adding it to the bottom with an if/else (there are clean up tasks at the end so I can't just let it crash) but have not had much success. Thanks!
Upvotes: 0
Views: 1785
Reputation: 156
If just checking whether the directory is empty or not, you could use. I run two times, one with two files in that directory and one with nothing.
check_files = list.files("C:/Users/.../Desktop/Rcheckfile")
check_files
[1] "abc.txt" "def.txt"
length(check_files)>0
[1] TRUE
check_files = list.files("C:/Users/.../Desktop/Rcheckfile")
check_files
character(0)
length(check_files)>0
[1] FALSE
You can use the result of the final comparison for further if or ifelse commands.
Upvotes: 2