Search code examples
blogdown

blogdown how to ingore an Rmd file that was built previously


I am using blogdown to build my site.

For a recent post, I wanted to keep a variable (config) out of the .Rmd post itself, because config contained sensitive authentication information. If I set config globally, but not in the .Rmd file itself, calling blogdown::serve_site() failed because config was not defined in the new session serve_site() creates when rendering the markdown files.

To accomplish what I wanted, I manually rendered the .Rmd source file with config defined in the global environment by calling rmarkdown::render("path/to/post.Rmd"), as suggested in how-to-use-objects-from-global-environment-in-rstudio-markdown. This successfully built the .Rmd file and produced the correct html output.

Now, though, I am unable to use blogdown::serve_site() to automatically build new posts on my site. It continually fails on the post that does not contain the required config variable. Is there a way to ignore the offending post? Or alternatively, a better way to do this?


Solution

  • Just like how you set global R options for blogdown (see Section 1.4 of the blogdown book), you can create config in .Rprofile under the root directory of your website project. The R code in .Rprofile will be executed before each Rmd post is rendered.