rstudio / distill

Distill for R Markdown
https://rstudio.github.io/distill/
Apache License 2.0
423 stars 57 forks source link

Some blog posts require two Knit compilations #389

Open Cdk29 opened 3 years ago

Cdk29 commented 3 years ago

It is a strange behavior that I don't know how to reproduce exactly. Last time I opened the https://github.com/rstudio/distill/issues/384 but I was not able to reproduce the following day for some reason.

When I knit an article, it compile until the end, create an md file and then ... restart. Or rerun the content of the rmd file, but this time it does not print out in the console the name of the rmd cells such as label: unnamed-chunk-42. I can see it rerunning everything from the top because of keras/tensorflow printing of training of a neural net.

Second point the index.xml files is updated only after the second compilation. Dunno why either.

The code of the blog is here : https://github.com/Cdk29/casualR , I will push the last article when the second training of the network will be done.

It occurs whether or not I am in a R project.

hardin47 commented 2 years ago

I have a similar error. I can't provide a reprex, but I took screenshots to explain the problem.

tl;dr -- the question is: why do i have to re-knit every blog post after I build the website? If I don't, the relevant index.html files get deleted, and the blog doesn't exist after I push to GitHub

  1. The important piece here is that my blog entries don't live in index.html (for the site), instead they live in daily.html. See the structure here:

image

  1. When I build the site, the relevant index.html file (connected to the blog entry) gets deleted!

image

  1. In order to obtain the necessary pieces of the website, I have to re-knit each blog entry (after every build):

image

  1. For reference, here is the index.Rmd file for the entire site:

image

And the daily.Rmd file:

image

The website is here: https://m154-comp-stats.netlify.app/

cderv commented 2 years ago

@hardin47 I don't think your issue is directly related to this one. I answered to your case in https://community.rstudio.com/t/distill-build-deletes-all-posts/126669/5 I think you are just missing a

site: distill::distill_website

in the main index.Rmd

cderv commented 2 years ago

@Cdk29 is your issue still happening ?

It is not easy to reproduce using your website as the post are quite heavy to rerun.

bschneidr commented 2 years ago

For what it's worth, I'm experiencing this issue too. I knit the blog post, and it gets to the point where it's created the ".knit.md" file, then it starts rerunning R code in the post.

In the example below, you can see it reruns a chunk of code that downloads data here:

trying URL 'https://www.bls.gov/oes/special.requests/oesm20ma.zip'
Content type 'application/x-zip-compressed' length 36365306 bytes (34.7 MB)
==================================================
downloaded 34.7 MB
RMarkdown Render Output ```r processing file: basic-fay-herriot-code.Rmd |. | 2% ordinary text without R code |... | 4% label: setup (with options) List of 1 $ include: logi FALSE |.... | 6% ordinary text without R code |...... | 8% label: unnamed-chunk-1 (with options) List of 3 $ echo : logi TRUE $ code_folding: chr "Show code to download data" $ cache : logi FALSE trying URL 'https://www.bls.gov/oes/special.requests/oesm20ma.zip' Content type 'application/x-zip-compressed' length 36365306 bytes (34.7 MB) ================================================== downloaded 34.7 MB |....... | 10% ordinary text without R code |......... | 12% label: unnamed-chunk-2 (with options) List of 2 $ echo : logi TRUE $ code_folding: chr "Show data processing code" Attaching package: 'dplyr' The following objects are masked from 'package:stats': filter, lag The following objects are masked from 'package:base': intersect, setdiff, setequal, union |.......... | 14% ordinary text without R code |........... | 16% label: unnamed-chunk-3 (with options) List of 1 $ echo: logi FALSE |............. | 18% ordinary text without R code |.............. | 20% label: unnamed-chunk-4 (with options) List of 3 $ fig.width : num 6 $ fig.height: num 8 $ out.width : chr "120%" |................ | 22% ordinary text without R code |................. | 24% label: unnamed-chunk-5 |................... | 27% ordinary text without R code |.................... | 29% label: unnamed-chunk-6 (with options) List of 3 $ fig.width : num 7.25 $ fig.height: num 12 $ out.width : chr "120%" `summarise()` has grouped output by 'SOC2', 'MAJOR_OCC'. You can override using the `.groups` argument. |..................... | 31% ordinary text without R code |....................... | 33% label: unnamed-chunk-7 Loading required package: coda Linked to JAGS 4.3.1 Loaded modules: basemod,bugs Loading required package: StanHeaders rstan (Version 2.21.5, GitRev: 2e1f913d3ca3) For execution on a local, multicore CPU with excess RAM we recommend calling options(mc.cores = parallel::detectCores()). To avoid recompilation of unchanged Stan programs, we recommend calling rstan_options(auto_write = TRUE) Do not specify '-march=native' in 'LOCAL_CPPFLAGS' or a Makevars file Attaching package: 'rstan' The following object is masked from 'package:coda': traceplot |........................ | 35% ordinary text without R code |.......................... | 37% label: unnamed-chunk-8 (with options) List of 4 $ output.var: chr "stanoutput" $ eval : logi FALSE $ echo : logi TRUE $ engine : chr "stan" |........................... | 39% ordinary text without R code |............................. | 41% label: unnamed-chunk-9 (with options) List of 2 $ echo: logi TRUE $ eval: logi FALSE |.............................. | 43% ordinary text without R code |............................... | 45% label: unnamed-chunk-10 (with options) List of 2 $ echo: logi TRUE $ eval: logi TRUE |................................. | 47% ordinary text without R code |.................................. | 49% label: unnamed-chunk-11 (with options) List of 2 $ echo: logi TRUE $ eval: logi FALSE |.................................... | 51% ordinary text without R code |..................................... | 53% label: unnamed-chunk-12 (with options) List of 2 $ echo: logi TRUE $ eval: logi FALSE |....................................... | 55% ordinary text without R code |........................................ | 57% label: unnamed-chunk-13 (with options) List of 1 $ echo: logi FALSE |......................................... | 59% ordinary text without R code |........................................... | 61% label: unnamed-chunk-14 (with options) List of 1 $ echo: logi TRUE |............................................ | 63% ordinary text without R code |.............................................. | 65% label: unnamed-chunk-15 (with options) List of 1 $ echo: logi TRUE |............................................... | 67% ordinary text without R code |................................................. | 69% label: unnamed-chunk-16 (with options) List of 1 $ echo: logi TRUE This is bayesplot version 1.9.0 - Online documentation and vignettes at mc-stan.org/bayesplot - bayesplot theme set to bayesplot::theme_default() * Does _not_ affect other ggplot2 plots * See ?bayesplot_theme_set for details on theme setting Scale for 'x' is already present. Adding another scale for 'x', which will replace the existing scale. |.................................................. | 71% ordinary text without R code |................................................... | 73% label: unnamed-chunk-17 (with options) List of 2 $ eval: logi FALSE $ echo: logi TRUE |..................................................... | 76% ordinary text without R code |...................................................... | 78% label: unnamed-chunk-18 (with options) List of 1 $ echo: logi FALSE |........................................................ | 80% ordinary text without R code |......................................................... | 82% label: unnamed-chunk-19 (with options) List of 1 $ echo: logi TRUE |........................................................... | 84% ordinary text without R code |............................................................ | 86% label: unnamed-chunk-20 |............................................................. | 88% ordinary text without R code |............................................................... | 90% label: unnamed-chunk-21 |................................................................ | 92% ordinary text without R code |.................................................................. | 94% label: unnamed-chunk-22 (with options) List of 2 $ warning: logi FALSE $ echo : logi FALSE |................................................................... | 96% ordinary text without R code |..................................................................... | 98% label: unnamed-chunk-23 (with options) List of 4 $ warning : logi FALSE $ echo : logi FALSE $ fig.width : num 7 $ fig.height: num 7 |......................................................................| 100% ordinary text without R code output file: basic-fay-herriot-code.knit.md "C:/Program Files/RStudio/bin/quarto/bin/pandoc" +RTS -K512m -RTS basic-fay-herriot-code.knit.md --to html5 --from markdown+autolink_bare_uris+tex_math_single_backslash --output basic-fay-herriot-code.html --lua-filter "C:\Users\benja\OneDrive\Documents\R\win-library\4.0\rmarkdown\rmarkdown\lua\pagebreak.lua" --lua-filter "C:\Users\benja\OneDrive\Documents\R\win-library\4.0\rmarkdown\rmarkdown\lua\latex-div.lua" --self-contained --standalone --variable toc-float=1 --highlight-style "C:/Users/benja/OneDrive/Documents/R/win-library/4.0/distill/rmarkdown/templates/distill_article/resources/arrow.theme" --template "C:\Users\benja\OneDrive\Documents\R\win-library\4.0\distill\rmarkdown\templates\distill_article\resources\default.html" "--metadata=link-citations:true" --include-in-header "C:\Users\benja\AppData\Local\Temp\RtmpOEfwCD\file55b07420716fhtml" --include-in-header "C:\Users\benja\AppData\Local\Temp\RtmpOEfwCD\file55b071a35e8fhtml" --include-in-header "C:\Users\benja\AppData\Local\Temp\RtmpOEfwCD\file55b01feb1e42html" --include-in-header "C:\Users\benja\AppData\Local\Temp\RtmpOEfwCD\file55b0b3516b6html" --include-in-header "C:\Users\benja\AppData\Local\Temp\RtmpOEfwCD\file55b05fce7e88html" --include-before-body "C:\Users\benja\AppData\Local\Temp\RtmpOEfwCD\file55b028c44128html" --include-before-body "C:\Users\benja\AppData\Local\Temp\RtmpOEfwCD\file55b011cf3d66html" --include-before-body "C:\Users\benja\AppData\Local\Temp\RtmpOEfwCD\file55b04f6d3f96html" --include-after-body "C:\Users\benja\AppData\Local\Temp\RtmpOEfwCD\file55b05c9d45d1html" --include-after-body "C:\Users\benja\AppData\Local\Temp\RtmpOEfwCD\file55b06391273ahtml" --include-after-body "C:\Users\benja\AppData\Local\Temp\RtmpOEfwCD\file55b010d33e71html" --mathjax --variable "mathjax-url=https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" --include-in-header "C:\Users\benja\AppData\Local\Temp\RtmpOEfwCD\rmarkdown-str55b04cad789b.html" --include-in-header "C:\Users\benja\AppData\Local\Temp\RtmpOEfwCD\file55b074e175a5html" trying URL 'https://www.bls.gov/oes/special.requests/oesm20ma.zip' Content type 'application/x-zip-compressed' length 36365306 bytes (34.7 MB) ================================================== downloaded 34.7 MB ```
bschneidr commented 2 years ago

The issue is definitely somehow related to #381. This stopped happening after I changed full_content from true to false in my site.yml:

rss:
  full_content: false
  categories:
    - R
hardin47 commented 2 years ago

My original problem was solved by adding a line to the YAML in index.Rmd. I had changed the index file because I was copying a different template (so had removed the distill line, and that line is vital to making the compilation work accurately). Here is the git blame:

https://github.com/hardin47/m154-comp-stats/commit/562de423d736702320b0f66c478db39cbaa6bf44

And the YAML is:

---
title: "Schedule"
description: |
  Schedule for Math 154, Computational Statistics, Fall 2021
site: distill::distill_website
---
cderv commented 2 years ago

Wow. Thanks @hardin47 for the feedback. That will really help me understand this issue better. Glad it works for you now, and we have a shared workaround. I'll try to improve the behavior or at least document it better.

In any case, yes this line is important - without it, I believe when you are calling rmarkdown::render_site(), the default R Markdown website generator will be used, instead of the distill one.