Skip to content
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

Remove temporary sanitized file when process is manually stopped in RStudio #2183

Closed
3 tasks done
jonocarroll opened this issue Oct 7, 2022 · 5 comments
Closed
3 tasks done

Comments

@jonocarroll
Copy link


By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.org/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('knitr'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('yihui/knitr').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.


If an input Rmd filename contains invalid characters (e.g. spaces; this is my filename.Rmd) then a temporary copy of the file with a sanitized filename is used when knitting (this-is-my-filename.Rmd) which is removed on completion. If the knit process is not completed (due to an error within a chunk) then this file is removed correctly (presumably via an on.exit()).

In RStudio, if the process is stopped via the Stop button then this hyphenated Rmd file is not deleted, and it blocks attempting to knit the file again, triggering the following (potentially confusing to the user, but entirely accurate) error

Error: The name of the input file cannot contain the special shell characters: [ <>()|\:&;#?*'] 
(attempted to copy to a version without those characters 'this-is-my-filename.Rmd' 
however that file already exists)
Execution halted

(possibly the issue causing #1110).

I don't fully appreciate how this RStudio button connects to the process of knitting, and this may actually be an RStudio bug (in which case I'm happy to re-file it over there), but perhaps there's another on.exit() to add here. I agree with the assessment in #1110 that this file shouldn't be overwritten, but if it was created as part of a failed knit, it should ideally be deleted.

The 'proper' solution would be that users don't create filenames containing these characters. One could dream.

xfun::session_info('knitr')

R version 4.2.1 (2022-06-23)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Monterey 12.6, RStudio 2022.2.3.492

Locale: en_AU.UTF-8 / en_AU.UTF-8 / en_AU.UTF-8 / C / en_AU.UTF-8 / en_AU.UTF-8

Package version:
evaluate_0.16 glue_1.6.2 graphics_4.2.1 grDevices_4.2.1 highr_0.9 knitr_1.40.2 magrittr_2.0.3 methods_4.2.1 stats_4.2.1 stringi_1.7.8
stringr_1.4.0 tools_4.2.1 utils_4.2.1 xfun_0.32 yaml_2.3.5

@yihui
Copy link
Owner

yihui commented Oct 7, 2022

This is not relevant to knitr but rmarkdown and RStudio IDE. More likely to be an RStudio issue. In rmarkdown, the sanitized file is generated here: https://github.com/rstudio/rmarkdown/blob/f764a66d20768750ca6c2adac18f6830e665a9ca/R/render.R#L367 and cleaned up here (via on.exit()): https://github.com/rstudio/rmarkdown/blob/f764a66d20768750ca6c2adac18f6830e665a9ca/R/render.R#L324

It sounds like on.exit() is not executed in this case if you click the Stop button in RStudio.

@jonocarroll
Copy link
Author

Thank you - that looks to be the case. I'll move this over to RStudio. Sorry for the noise.

@yihui
Copy link
Owner

yihui commented Oct 7, 2022

No worries. I tried to come up with a minimal reproducible example without rmarkdown, but didn't manage to create one.

@yihui
Copy link
Owner

yihui commented Oct 7, 2022

For the record, we have also run into a similar issue before in bookdown: rstudio/bookdown#986 (comment)

@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants