3

I have an Rmd file that I want to convert to a pdf file. Currently it is located in a subfolder of the "static" folder that is a part of my blog site structure created by the blogdown package. The problem is, when I hit the "Knit" button in RStudio, it calls rmarkdown::render_site(...) while I was expecting rmarkdown::render(...). I do have a file R/build.R with a single line of a command blogdown::build_dir("static") so this is weird to me. When I tried to convert other Rmd files in a different folder (not associated with my blog folders/files) everything works perfectly fine as expected.

To get what I want, I am currently typing rmarkdown::render("myfile.Rmd") in the console, or I am using infinite moon reader, but neither is as convenient as the "Knit" button :(

The following is the output from xfun::session_info('blogdown') after updating the blogdown package to ver 1.1:

> xfun::session_info('blogdown')
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363), RStudio 1.4.1103

Locale:
  LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
  LC_NUMERIC=C                           LC_TIME=English_United States.1252    

Package version:
  base64enc_0.1.3 BH_1.75.0.0     blogdown_1.1    bookdown_0.21   digest_0.6.27   evaluate_0.14   glue_1.4.2     
  graphics_4.0.3  grDevices_4.0.3 highr_0.8       htmltools_0.5.0 httpuv_1.5.4    jsonlite_1.7.2  knitr_1.30     
  later_1.1.0.1   magrittr_2.0.1  markdown_1.1    methods_4.0.3   mime_0.9        promises_1.1.1  R6_2.5.0       
  Rcpp_1.0.5      rlang_0.4.9     rmarkdown_2.6   servr_0.21      stats_4.0.3     stringi_1.5.3   stringr_1.4.0  
  tinytex_0.29    tools_4.0.3     utils_4.0.3     xfun_0.20       yaml_2.2.1     

edited: I am not absolutely sure if this will help, but the HW3.Rmd file I want to convert to pdf goes like the following:

---
title: "Homework 3"
subtitle: "due Feb 2, 2021"
output:
  pdf_document: default
---

```{r}
1 + 1
```

When I save this file in the folder as in C:/Users/jungl/Dropbox/GitHub/blog2020/static/Drexel_2021/HW3.Rmd (here C:/Users/jungl/Dropbox/GitHub/blog2020 is the root folder that holds all folders/files created by blogdown), the "Knit" button calls, unexpectedly, rmarkdown::render_site(...). However, when I copy the same HW3.Rmd in a folder as in C:/Users/jungl/Dropbox/test/HW3.Rmd, "Knit" button works as expected and calls rmarkdown::render(...). So it looks like the "Knit" button of RStudio somehow automatically determines whether it should call rmarkdown::render_site(...) or rmarkdown::render(...) based on whether the Rmd file under work is located in a (sub)folder of the root folder that holds blogdown-generated folders/files.

edited: The Github repo is at https://github.com/junglee0713/blog2020 and I just checked that the same problem still persists. The HW3.Rmd file that I want to convert to PDF is in https://github.com/junglee0713/blog2020/tree/master/static/Drexel_2021

Yet another edit: installing the dev version of blogdown seems to solve the problem (output below, note it still calls rmarkdown::render_site(...)), but with another issue. It renders other Rmd files in the same directory, say HW1.Rmd and HW2.Rmd, to respective PDF files.

==> rmarkdown::render_site('C:/Users/jungl/Dropbox/GitHub/blog2020/static/Drexel_2021/HW3.Rmd',  encoding = 'UTF-8');
  |..................                                                    |  25%
  ordinary text without R code

  |...................................                                   |  50%
label: setup (with options) 
List of 1
 $ include: logi FALSE



processing file: HW3.Rmd
  |....................................................                  |  75%
  ordinary text without R code

  |......................................................................| 100%
label: unnamed-chunk-1 (with options) 
List of 1
 $ eval: symbol F


"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS HW3.utf8.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output HW3.tex --lua-filter "C:\Users\jungl\Documents\R\win-library\4.0\rmarkdown\rmarkdown\lua\pagebreak.lua" --lua-filter "C:\Users\jungl\Documents\R\win-library\4.0\rmarkdown\rmarkdown\lua\latex-div.lua" --self-contained --highlight-style tango --pdf-engine pdflatex --variable graphics --variable "geometry:margin=1in" 
output file: HW3.knit.md


Output created: HW3.pdf
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

So each time I render HW3.Rmd to a PDF, I get unsolicited updates of HW1.pdf and HW2.pdf too (as you see, I don't have any ggplot figure in HW3.Rmd and the output warns about picking better value with binwidth. HW2.Rmd does have geom_histogram() in it). What's more interesting to me is that in the folder where HW1.Rmd, HW2.Rmd, and HW3.Rmd are located, there are other Rmd files I convert to HTML (say Drexel_2021_Lecture_1.Rmd, Drexel_2021_Lecture_2.Rmd, and Drexel_2021_Lecture_3.Rmd -- they are xaringan slides) and they don't get affected by the knitting.

  • It'll be very helpful if you could provide the output of `xfun::session_info('blogdown')` in your post. – Yihui Xie Jan 21 '21 at 18:15
  • Thanks! I will post the outut from xfun::session_info('blogdown') below. However, I still have the same issue. The following is what I get after hitting the "Knit" button: ==> rmarkdown::render_site('C:/Users/jungl/Dropbox/GitHub/blog2020/static/Drexel_2021/HW3.Rmd', encoding = 'UTF-8'); Rendering static/Drexel_2021/HW3.Rmd... Done. – Jung-Jin Lee Jan 22 '21 at 05:02
  • In the future, please add the session info into your original post (you can edit it anytime), instead of posting it as an answer, since it's not an answer. I did it for you this time. Now I could you please provide a reproducible example? Because this is not reproducible in my own testing. – Yihui Xie Jan 22 '21 at 17:28
  • Thank you Yihui for editing my original post -- now I deleted the `xfun::session_info('blogdown')` from the answers following your suggestion. – Jung-Jin Lee Jan 22 '21 at 21:30
  • You are welcome! If you provide a reproducible example, it will be much easier for me to help you. – Yihui Xie Jan 23 '21 at 04:29
  • I added an example(?) to the original post, not sure though if this could be regarded as _reproducible_. – Jung-Jin Lee Jan 24 '21 at 05:32
  • Thanks, but I need the full website. A single Rmd file is not enough. You can make a copy of your current website project, delete other irrelevant files in the project, make sure the problem is still reproducible, and upload the project somewhere that I can download (e.g., make it a Github repo, or compress it to a zip file and share with Dropbox, etc.). – Yihui Xie Jan 24 '21 at 15:46
  • Thanks Yihui! The Github repo is at `https://github.com/junglee0713/blog2020` and I just checked that the same problem still persists. The `HW3.Rmd` file that I want to convert to PDF is in `https://github.com/junglee0713/blog2020/static/Drexel_2021` – Jung-Jin Lee Jan 24 '21 at 17:21
  • By the way, the use of four backticks ```` is so cool! – Jung-Jin Lee Jan 24 '21 at 17:23
  • More about the four backticks: https://yihui.org/en/2017/05/four-backticks-github/ I still can't reproduce your problem. When I click the Knit button, it generates the PDF correctly. Please see my updated answer and try the dev version of **blogdown**. If it still doesn't work, I guess we have to do a video chat with screen-sharing so I can possibly figure out what's wrong. – Yihui Xie Jan 24 '21 at 19:48
  • Thank you for the link to the very interesting post on the backticks! – Jung-Jin Lee Jan 24 '21 at 23:33

1 Answers1

2

When you click the "Knit" button, blogdown does call rmarkdown::render_site() first, but this function actually calls rmarkdown::render() eventually.

If it doesn't compile your Rmd file to PDF when you click the Knit button, please make sure you are using the latest version of blogdown, because it sounds like a bug that I have fixed a few months ago (when in doubt, try to update packages).

If you install the current development version of blogdown (restart R after installation):

install.packages('blogdown', repos = c(
  rstudio = 'https://rstudio.r-universe.dev',
  CRAN = 'https://cloud.r-project.org'
))

you will see detailed log of knitting in the R Markdown tab when you click the Knit button:

The R Markdown tab

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
  • I updated the blogdown package to version 1.1. Still the same issue though – Jung-Jin Lee Jan 22 '21 at 05:03
  • Thank you so much! Installation of the dev version seems to solve the problem, but this time it renders some of other Rmd files in the same directory to PDF as well (maybe this was the case in the previous version of blogdown as well and I might not have noticed), as described in the newly edited part of the original post. – Jung-Jin Lee Jan 24 '21 at 23:35
  • Great! I'm glad that we are making progress. It shouldn't render other Rmd files. It sounds like a problem of `R/build.R` or `blogdown::build_dir()`. I guess I know how to fix it, and I'll look into it tomorrow. – Yihui Xie Jan 25 '21 at 06:18
  • @Jung-JinLee You can reinstall the dev version of blogdown (v1.1.7) and it should resolve the problem now. – Yihui Xie Jan 25 '21 at 21:36
  • 1
    Hi Yihui, **problem completely solved!!** Thank you so much for your time and effort so far, and for your great packages/books that benefit the whole R community! – Jung-Jin Lee Jan 26 '21 at 04:16
  • Good to know! I'm glad that it finally worked. Thanks for the nice words! – Yihui Xie Jan 26 '21 at 06:09