Repository navigation
Description
I am facing a strange issue in last 2-3 days. I am unable to knit any .Rmd file to any format (HTML/PDF/Word). First, I create an RStudio Project. Within the RStudio Project, from RStudio File Menu>New File > R Markdown, I choose any of the three output formats. I simply save the document without making any changes in the defaults in the Rmd file. Then I press the "knit" button in RStudio. I get the following error while rendering it.
processing file: _main.Rmd
Error in parse_block(g[-1], g[1], params.src, markdown_mode) :
Duplicate chunk label 'setup', which has been used for the chunk:
knitr::opts_chunk$set(echo = FALSE)
Calls: <Anonymous> ... process_file -> split_file -> lapply -> FUN -> parse_block
Please delete _main.Rmd after you finish debugging the error.
Execution halted
Isn't _main.Rmd supposed to be in bookdown? How can I get this error while knitting a single R Markdown file? Moreover, this _main.Rmd file is saved in a different location - it's the default working directory (while not in a project).
Irrespective of this, if I try to knit it again, I get the error message
Error in render_book(input_file, output_format, envir = envir, preview = TRUE) :
The file _main.Rmd exists. Please delete it if it was automatically generated. If you are sure it can be safely overwritten or deleted, please set the option 'delete_merged_file' to true in _bookdown.yml.
Calls: <Anonymous> -> <Anonymous> -> <Anonymous> -> render_book
Execution halted
So, again it confirms that the underlying function is from bookdown instead of R Markdown.
I have updated all the relevant software - downloaded knitr, R Markdown and bookdown from github. I have also installed latest daily build of tinytex (using tinytex::install_prebuilt("TinyTeX"))and RStudio. The session info is as follows;
xfun::session_info("Rmarkdown")
R version 4.1.3 (2022-03-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044), RStudio 2022.6.0.270
Locale:
LC_COLLATE=English_India.1252
LC_CTYPE=English_India.1252
LC_MONETARY=English_India.1252
LC_NUMERIC=C
LC_TIME=English_India.1252
system code page: 65001
Package version:
Rmarkdown_2.13.3
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
cderv commentedon Apr 7, 2022
From all those error, I would say rmarkdown or RStudio IDE is kind of detecting you are in a bookdown project.
Are you working in a project ? Or are you working in a default working directory with all those files around ?
It is best to work in projects to avoid those type of issues.
Is
rmarkdown::render()in console working ok ?bhattmaulik commentedon Apr 7, 2022
I am working in an RStudio Project, not in the default working directory. But despite that, the _main.Rmd file is saved in the default working directory instead of the project's directory.
And as you have asked, I tried rmarkdown::render(input_file = "filename", output_format = "pdf_document"). It is working as expected. I again updated the RStudio daily build from 2022.6.0.270 to 2022.6.0.277. But the problem continues with that version as well.
cderv commentedon Apr 7, 2022
This means it is something related to RStudio IDE. what is the function called when you are clicking the knit / render button ?
Should be written in the build or rmarkown pane. thanks !
bhattmaulik commentedon Apr 8, 2022
When I press the knit button, the function being called is rmarkdown::render_site. This is what I get in the "render" tab
After your message, I uninstalled the RStudio IDE, and reinstalled it again. But still the problem continues.
bhattmaulik commentedon Apr 8, 2022
So, as a workaround, I added one more line in the YAML header of the .Rmd file
After this, I could compile it properly. But it also means that I will have to add this line to all the R Markdown documents now onwards, unless and until the behavior of the Knit button changes. I will have to add this line even to the old R markdown documents that I have prepared earlier. How can I change the default behavior of the Knit button now?
yihui commentedon Apr 8, 2022
Could you share the whole project? You can compress it into a zip archive and upload here. It's hard to tell what's wrong without a reproducible example.
bhattmaulik commentedon Apr 8, 2022
TeXLive.zip
Please check this file. I am just trying to arrange all the tinytex packages in descending order of their sizes. I have installed these packages using tinytex:::install_prebuilt("TinyTeX). I have not added the extra line in YAML header yet (knit: rmarkdown::render). So, here in my computer, I am still getting that same error while knitting the document. This happens irrespective of the output format I choose - be it HTML/Word/PDF.
Thank you for your continuous support.
Regards,
Maulik.
yihui commentedon Apr 8, 2022
That's really odd. I can't reproduce the problem, and can't think of a reason why RStudio would treat any of your Rmd file as a bookdown project. What is your project option
Tools -> Project Options -> Build Tools?bhattmaulik commentedon Apr 8, 2022
The Project Build Tools: (None)
yihui commentedon Apr 8, 2022
That's correct. Then I really don't know how your RStudio ended up in that weird state. Do you have anything suspicious in your
~/.Rprofilefile? Or do you have a~/.RDatafile?Perhaps the last suggestion that I could give is reset RStudio: https://support.rstudio.com/hc/en-us/articles/200534577-Resetting-RStudio-Desktop-s-State If that doesn't work, I'll be out of ideas.
bhattmaulik commentedon Apr 8, 2022
I don't save .RData file. And I haven't created .Rprofile file either.
I have finally put this question on RStudio Community as to how to change the default behavior of knit button in RStudio. If I find a solution there, I would intimate here, and close the issue. Thanks a lot for your support.
bhattmaulik commentedon Apr 8, 2022
On further experiments, when I uninstalled bookdown package, and then tried knitting the document through "Knit" button, it knits properly, but I get an error:
Error in loadNamespace(x) : there is no package called ‘bookdown’At this time, I can see in the "Render" tab that the knit button is taking rmarkdown::render function to knit the document. I can knit in all the three formats (word, html and pdf).
But when I re-install the bookdown package, the knit button again starts taking rmarkdown::render_site function to knit the document. That means, the behavior of "knit" button is different when bookdown package is present.
cderv commentedon Apr 8, 2022
Can you run
I believe this is what RStudio IDE is using to decide if it is a website project.
Basically, it would been seen as a bookdown project if you have a
index.Rmdfile with a YAML fieldsite: bookdown::bookdown_sitelike in a bookdown project.We recently had issues with our internal
proj_root()function and tweak it. Maybe there is still issue with it.I wonder if what happens is that your current project is located in a subfolder somehow of another folder/project that would have and
index.Rmdwithsitekey.Thank you.
bhattmaulik commentedon Apr 8, 2022
You are probably right. I don't fully understand the output of these functions you have suggested, but I have still followed your suggestion. I am attaching the results here.
debug.pdf
cderv commentedon Apr 8, 2022
Yes this is it. The results you shared shows that a book project website is detected, and that is why the IDE is behaving as in a book project. It seems it comes from
E:/Maulik/Projectsfolder seems to have aindex.Rmdfile withsite: bookdown::bookdown_siteproject.Can you check that ? If that is correct, is that
index.Rmdthere for a reason ?That being said, I don't think we have a correct behavior here.
We should not probably check for website project that far up the current folder. I am thinking we should stop at the root of the RStudio project (when
.Rprojis found in the current root being checked).@yihui does it feel off to you too ?
4 remaining items
cderv commentedon Apr 8, 2022
@bhattmaulik if would help if you can test #2345 ?
`site_generator()` stops search at RStudio project root (#2345)
cderv commentedon Apr 8, 2022
@bhattmaulik this is now in dev version of rmarkdown
Thanks!
bhattmaulik commentedon Apr 8, 2022
I just checked it. I had both the files (index.Rmd and _main.Rmd) in the global root directory, and yet the Rmd file inside an RStudio project knitted a pdf file without any trouble. Thank You!
github-actions commentedon Oct 11, 2022
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.