Skip to content

Suppress rendering of empty canvas created by graphics device side-effects #96

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

Open
yjunechoe opened this issue May 23, 2025 · 4 comments

Comments

@yjunechoe
Copy link

This concerns the side-effect of functions like grid::convertUnit() which requests information from the graphics device. If a graphics device is not available, R will open one as a side-effect. The issue concerns whether this then gets rendered as an image.

litedown will render an empty canvas in these cases:

Image

In rmarkdown (and quarto), the rendering is suppressed:

Image

I'm not sure how it's implemented in rmarkdown/quarto, but if it's not too much hassle I think this behavior is desirable to implement for litedown. Please LMK what you think!


Reprex:

f <- tempfile(fileext = ".Rmd")
writeLines("
---
title: reprex
---

```{r}
library(grid)
g <- pointsGrob()
x <- convertUnit(g$x, 'mm')
x
```
", f)
rmarkdown_html <- rmarkdown::render(f)
browseURL(rmarkdown_html)
litedown_html <- litedown::fuse(f)
browseURL(litedown_html)
@yihui
Copy link
Owner

yihui commented May 23, 2025

I'll see if I can suppress this empty plot. In the mean time, you can use the chunk option fig.path = NULL to avoid capturing the plot on litedown's side: https://yihui.org/litedown/#sec:option-fig Thanks for the report!

@yjunechoe
Copy link
Author

Thanks for the quick response!

Apologies if I'm misunderstanding, but fig.path = NULL doesn't seem to prevent the plot from being rendered for me. Am I doing this correctly?

---
knit: litedown:::knit
---

```{r, fig.path = NULL}
library(grid)
g <- pointsGrob()
x <- convertUnit(g$x, 'mm')
x
```

@yihui
Copy link
Owner

yihui commented May 24, 2025

Sorry I meant fig.path = NA instead of NULL.

@yjunechoe
Copy link
Author

Thanks, that worked!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants