If you are using Windows 10, it's possible that Controlled Access Folder is blocking something called "Rterm.exe" and you need to add it to the allowed apps list.
For context, I was trying to knit the prepopulated RMarkdown file template but got an error similar to what you received:
processing file: Lesson01_R_Markdown_Intro.Rmd
|................................................... | 86% [pressure]Error in file(con, "w") : cannot open the connection
Calls: <Anonymous> ... signalCondition -> <Anonymous> -> write_utf8 -> writeLines -> file
In addition: Warning messages:
1: In dir.create(dirname(name), recursive = TRUE) :
cannot create dir 'Lesson01_R_Markdown_Intro_files', reason 'No such file or directory'
2: In png(..., res = dpi, units = "in") :
unable to open file 'Lesson01_R_Markdown_Intro_files/figure-html/pressure-1.png' for writing
3: In png(..., res = dpi, units = "in") : opening device failed
4: In file(con, "w") :
cannot open file 'Lesson01_R_Markdown_Intro.knit.md': No such file or directory
Execution halted
At first, I thought it was a caching issue after reading some Stackoverflow posts. The answers I saw suggested restarting RStudio. However, this didn't work for me. I then looked to see if Windows may be blocking something because Windows blocks a lot of R and RStudio related files.
An executable file called "Rterm.exe" seems to be the one that is trying to trigger the RMarkdown HTML page. However, due to security protocols on Windows 10 end, this (and other R/RStudio executable files) are blocked because they are trying to access protected folders. You have to allow this executable to access your protected folders.
If you navigate to the Controlled Access Folder (just search for it using the Windows search), you'll be able to see the blocked list by clicking "Block History".
To allow an executable access to your protected folders, you need to:
- Click "Allow an app through Controlled Folder access"
- Click "Add an allowed app"
- Click "Recently blocked apps"
- Click the + for all R/RStudio related executables
Please note: There may be two Rterm.exe (one possibly within your Programs folder and another one within a PROGA~1 folder). Add both to the allowed apps list.
You may have other files you need to add as well. Please see the image link below:
Image of all R and RStudio executables to allow
Once you do that, restart RStudio and you should be able to knit (should look like below)
processing file: Lesson01_R_Markdown_Intro.Rmd
"C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/pandoc" +RTS -K512m -RTS Lesson01_R_Markdown_Intro.knit.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output Lesson01_R_Markdown_Intro.html --lua-filter "C:\Users\~~~~~~\AppData\Local\R\WIN-LI~1\4.3\RMARKD~1\RMARKD~1\lua\PAGEBR~1.LUA" --lua-filter "C:\Users\~~~~~~\AppData\Local\R\WIN-LI~1\4.3\RMARKD~1\RMARKD~1\lua\LATEX-~1.LUA" --embed-resources --standalone --variable bs3=TRUE --section-divs --template "C:\Users\~~~~~~~~~\AppData\Local\R\WIN-LI~1\4.3\RMARKD~1\rmd\h\DEFAUL~1.HTM" --no-highlight --variable highlightjs=1 --variable theme=bootstrap --mathjax --variable "mathjax-url=https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" --include-in-header "C:\Users\~~~~~~\AppData\Local\Temp\RtmpMF1t6W\rmarkdown-str34846a645384.html"
output file: Lesson01_R_Markdown_Intro.knit.md
Output created: Lesson01_R_Markdown_Intro.html
I hope this helps :)!