Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

checking on success of write.csv in R

Tags:

r

In R, how do I verify that write.csv(my.data.frame, file='test.csv') was successful without re-reading it in again? It doesn't seem to return anything. I was thinking of doing a file.exists('test.csv') and then grabbing a timestamp before and after the write.csv() and checking that the timestamp on the file is between the two? Any suggestions?

like image 659
Sean Avatar asked Nov 22 '12 11:11

Sean


1 Answers

You may use the function try():

res <- try(write.csv(1:100, "SOME GOOD PATH/temp.csv"))
is.null(res)
# [1] TRUE
res <- try(write.csv(1:100, "SOME BAD PATH/temp.csv"))
is.null(res)
# [1] FALSE
class(res)
# [1] "try-error"
like image 191
Ali Avatar answered Sep 30 '22 06:09

Ali