rmarkdown icon indicating copy to clipboard operation
rmarkdown copied to clipboard

wrongly placed plot in html_notebook when markdown content is generated with R

Open SamuelAllain opened this issue 1 year ago • 3 comments

Hello, I try to dynamically generate markdown sections with plots and I have very weird behaviours both when I compare html_document and html_notebook and when I compare with a constant plot and with a variable plot. The reprex talks for itself :

---
title: "R Notebook"
output:
  html_document: default
  html_notebook: default
---



```{r, results='asis'}
for (i in 1:5) {
  # Section
  cat(sprintf("\n# Test %s\n", i))
  
  # plot(mtcars[,c(i, 3)])
  # Works well with html_document, not with html_notebook which has a weird behaviour, nothing in first section
  
  plot(mtcars[,c(2, 3)])
  # doesn't work with neither output :
  # - html_document keeps only one graphic, randomly putting it into section "test 2"
  # - html_notebook has the same weird behaviour as previous cas (c(i,3))
  
  cat("\n")
}

xfun::session_info('rmarkdown') gives

R version 4.2.1 (2022-06-23)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.5 LTS, RStudio 2022.7.2.576

Locale:
  LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
  LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
  LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
  LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

Package version:
  base64enc_0.1.3 bslib_0.4.0     cachem_1.0.6    digest_0.6.30   evaluate_0.19   fastmap_1.1.0  
  fs_1.5.2        glue_1.6.2      graphics_4.2.1  grDevices_4.2.1 highr_0.10      htmltools_0.5.3
  jquerylib_0.1.4 jsonlite_1.8.3  knitr_1.41.9    magrittr_2.0.3  memoise_2.0.1   methods_4.2.1  
  R6_2.5.1        rappdirs_0.3.3  rlang_1.0.6     rmarkdown_2.17  sass_0.4.2      stats_4.2.1    
  stringi_1.7.8   stringr_1.4.1   tinytex_0.42    tools_4.2.1     utils_4.2.1     xfun_0.36      
  yaml_2.3.6     

Pandoc version: 2.19.2

Checklist

When filing a bug report, please check the boxes below to confirm that you have provided us with the information we need. Have you:

  • [x] formatted your issue so it is easier for us to read?

  • [x] included a minimal, self-contained, and reproducible example?

  • [x] pasted the output from xfun::session_info('rmarkdown') in your issue?

  • [x] upgraded all your packages to their latest versions (including your versions of R, the RStudio IDE, and relevant R packages)?

  • [x] installed and tested your bug with the development version of the rmarkdown package using remotes::install_github("rstudio/rmarkdown")?

SamuelAllain avatar Jan 12 '23 09:01 SamuelAllain