Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error=TRUE not honored with certain ggplot2 errors #2363

Closed
5 tasks done
sjspielman opened this issue May 25, 2022 · 6 comments
Closed
5 tasks done

error=TRUE not honored with certain ggplot2 errors #2363

sjspielman opened this issue May 25, 2022 · 6 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@sjspielman
Copy link

sjspielman commented May 25, 2022

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:

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

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

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

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

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

Bug Report

I am filing this issue because I am observing circumstances where error=TRUE is not honored in code chunks. When the chunk contains ggplot2 code and the error is related to an incorrect aes() specification, it seems that rmarkdown is expecting to include an output image associated with that chunk. There should not be any image, because error=TRUE. Other errors in ggplot2 code that are not related to incorrectly specified aes() arguments do not have this problem - error=TRUE is honored and the document knits. Similarly, base R graphics plots with errors do not prevent knitting.

I have included here an Rmarkdown file and its rendered HTML with several chunks that demonstrate what I am seeing. I have commented out the chunks that prevent knitting in spite of error=TRUE. When I uncomment these chunks, the document does not render with errors that I include in the comments within.
potential_bug.zip
Note that I originally observed this with rmarkdown 2.14, so I installed 2.14.1 and the problem remained (hence it's in the sessionInfo() in the rendered HTML.)

The Rmarkdown itself contains a sessionInfo() chunk relevant to what is in the environment during knitting, but either way I am also pasting my sessionInfo() from Console below:

> sessionInfo()
R version 4.2.0 (2022-04-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.3.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] compiler_4.2.0   fastmap_1.1.0    cli_3.3.0        htmltools_0.5.2  tools_4.2.0     
 [6] yaml_2.3.5       rmarkdown_2.14.1 knitr_1.39       xfun_0.31        digest_0.6.29   
[11] rlang_1.0.2      evaluate_0.15   
@yihui yihui added the bug an unexpected problem or unintended behavior label May 25, 2022
@yihui yihui moved this to Backlog in R Markdown Team Projects May 25, 2022
@yihui yihui moved this from Backlog to In Progress in R Markdown Team Projects May 25, 2022
Repository owner moved this from In Progress to Done in R Markdown Team Projects May 25, 2022
@yihui
Copy link
Member

yihui commented May 25, 2022

@sjspielman That's really a great bug report! Should be fixed in the dev version of evaluate now:

remotes::install_github('r-lib/evaluate')

Thanks!

@cderv If you have time, please help with adding tests to https://github.com/r-lib/evaluate/blob/main/tests/testthat/test-graphics.r At least we should expect

evaluate::evaluate('library(ggplot2); ggplot(iris) +
  aes(x = Speciess, y = Sepal.Length) + 
  geom_boxplot()')

evaluate::evaluate('library(ggplot2); ggplot(iris) +
  aes(x = Species, y = Sepal.Length) + 
  geom_bar()')

not to contain recorded plots (because the plots are empty). Thanks! BTW, its Github actions may need to be updated, too.

@cderv
Copy link
Collaborator

cderv commented May 25, 2022

I can add those tests yet.

It is interesting to see though that I can't reproduce on windows the issues in the Rmd file shared.
error1-1.png and error2-1.png are created and on disk, so they are found and setting error = TRUE does not prevent knitting. Everything is included in the output, the errors and the empty graphics (as you would get in R console + Viewer)

Using dev version of evaluate, I get the no error as expected, and this time empty graphics are not included.

Just wanted to share this. I'll add the test for the later case

@cderv
Copy link
Collaborator

cderv commented May 25, 2022

@yihui I added test in evaluate for this change you made.

@yihui
Copy link
Member

yihui commented May 25, 2022

Thanks!

Everything is included in the output, the errors and the empty graphics (as you would get in R console + Viewer)

I didn't get an error (on macOS), either. The HTML output page was generated without an error (no R or Pandoc errors), but the empty images were displayed as the icons for missing images, so I thought we should not generate such plots in the first place.

@cderv
Copy link
Collaborator

cderv commented May 25, 2022

but the empty images were displayed as the icons for missing images

Ok. On my side, I had the images and the files, but blank images. Anyway, this is fixed.

clrpackages pushed a commit to clearlinux-pkgs/R-evaluate that referenced this issue Aug 12, 2022
… 0.16

Christophe Dervieux (2):
      Update GHA workflows (#109)
      Test that empty ggplot are not recorded (#110)

Yihui Xie (3):
      start the next version
      fix rstudio/rmarkdown#2363: ignore empty plots that only contain calls to requireNamespace()
      CRAN release v0.16
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
Archived in project
Development

No branches or pull requests

3 participants