I'm writing simple code in R where I'm checking whether given file exists in the working directory and if it doesn't I'm downloading zip file with the data and unzipping it in R. As it happens, if the file exists the R objects corresponding to binary (getBinaryURL) and connection to the file are connected. I would like to remove them after successful download. I drafted those one sentence if statements but they return error Error in exists(bin) : invalid first argument. It's intermediately obvious to me what's wrong with the syntax.
if (exists(bin)) rm(bin)
if (exists(con)) rm(con)
if (exists(dataurl)) rm(dataurl)
Your if()
statement isn't the problem, you need to quote the object passed to exists()
.
> AnObject <- seq(1:10)
> exists(AnObject)
Error in exists(AnObject) : invalid first argument
> exists("AnObject")
[1] TRUE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With