I want to delete a file, and once that file is deleted continue with my R script.
For example:
Create a folder with a .csv in it
dir <- getwd()
dir.create(file.path(dir, "folder"), showWarnings = FALSE)
df <- matrix(1:100000,nrow=1000)
write.csv(df,file.path(dir,"folder/test.csv"))
Now if I run unlink()
it will not wait until the unlink is done to execute the next line. This leaves file.still.there
as TRUE
unlink(file.path(dir, "folder"),recursive = T)
file.still.there <- file.exists(file.path(dir, "folder"))
I know I can use Sys.sleep()
, but is there a way to do this dynamically. Depending on the size of the folder it seems to take longer to delete.