New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add recursive = TRUE to unlink functions in render.R #577
Conversation
Without recursive = TRUE, files are not getting deleted. See reproducible example (at least on my machine) below:
```{r}
tempFile = tempfile('render', '.', '.rds')
print(tempFile)
file.exists(tempFile) ### returns FALSE, nothing written to file
## write something to file
writeLines("This is a temp file", con = tempFile)
file.exists(tempFile) ### returns TRUE
## use unlink with default value of recursive = FALSE
unlink(tempFile)
## check if file exists
file.exists(tempFile) ### returns TRUE, file still exists!
## use unlink with default value of recursive = FALSE
unlink(tempFile, recursive = TRUE)
## check if file exists
file.exists(tempFile) ### returns FALSE, finally got rid of it
## I do not know why this option needs to be TRUE as it does not
## seem we are doing a recursive search down a directory tree.
## My only guess is it has something to to with the path specification
## as tempFile = ".\\render2b885fcas674b.rds" and I am not familiar
## with the ".\\" notation.
Added recursive = TRUE to other unlinks in the render file. The previous commit worked so well, that this seemed like a good idea to save Yihui some time.
|
So basically A path |
|
I debugged a little more and it turns out having something to do with my use of OneDrive. It turns out that if the file is created in a OneDrive synced working directory, PS: Thanks for the path notation answer. My true confusion with the path is the double backslash ".\\render...". I would have just used a single backslash when defining the file path. |
|
In R (and many other languages), when you see double backslashes in a character string, it means a single literal backslash (yes, this is confusing forever: https://xkcd.com/1638/). One more test I need you to help me with: does tempFile = basename(tempfile('render', '.', '.rds')) |
|
The behavior is unchanged with Thanks for the cartoon ... makes me feel better about my confusion :-) |
I think file.remove() makes better sense in this case. Thanks!
The creation of temp files using the
tempfile()function creates files with a path of ".\\filename". However, when using theunlinkfunction with default ofrecursive = FALSE, these created temp files are not removed as expected. Whenrecursive = TRUEis added to the unlink function call, then it works. Code which reproduces the problem on my machine is below: