-
-
Notifications
You must be signed in to change notification settings - Fork 879
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
Display all plots in a for loop (knitted roxygen2 documentation) #2392
Comments
@grantmcdermott First of all, I absolutely love tinyplot! This issue might belong to pkgdown. I'm not 100% sure since I don't know how pkgdown runs examples, but I'm reasonably sure litedown should work fine: https://yihui.org/litedown/#sec:package-sites-via-github-action (I can verify it tomorrow morning) |
Super, thanks @yihui. We actually use I've been keeping half an eye out on |
Hi there, I just want to clarify this is not related to
then:
|
This is definitely knitr + evaluate behavior as you can reproduce by @yihui do you know exactly the reason / design in knitr which you change in fuse ? I believe this is limitation of knitr and recommended way to output several content like that is to use child document (https://bookdown.org/yihui/rmarkdown-cookbook/child-document.html) Here is what would work in rmarkdown and quarto right now ```{r}
#| results: asis
res <- lapply(thms, function(thm) {
res <- knitr::knit_child(text = c(
"```{r echo = FALSE}",
"tinytheme(thm)",
"tinyplot(I(Sepal.Length * 1e4) ~ Petal.Length | Species, data = iris)",
"```"
), envir = environment(), quiet = TRUE)
})
cat(unlist(res), sep = "\n")
```
|
@etiennebacher Thanks! That's super helpful! @cderv I think the problem comes from the evaluate package, which knitr uses to run code and capture plots. Due to the way it works (via That said, this problem might be fixable in evaluate. I'm not 100% sure---it depends on whether the |
Thanks @yihui - really helpful ! I see what you are mentionning about record plot. I would think At first, I thought this was related to the fact that For example, this won't print anything as this is inside a for loop.
Maybe evaluate related too. I'll have a look |
It's true that for |
I think the plot issue is related to which was recently closed. Basically res <- evaluate::evaluate(function(){
library(tinyplot)
tinytheme("dark")
tinyplot(I(Sepal.Length * 1e4) ~ Petal.Length | Species, data = iris)
tinytheme("minimal")
tinyplot(I(Sepal.Length * 1e4) ~ Petal.Length | Species, data = iris)
}) will see all the plots res <- evaluate::evaluate(function(){
library(tinyplot)
for (thm in c("dark", "minimal")) {
tinytheme(thm)
tinyplot(I(Sepal.Length * 1e4) ~ Petal.Length | Species, data = iris)
}
}) will see only the last one. So definitely related to for-loop context and not just plot change detection I think.. |
Oh wait a minute. These plots also differ in BTW, here is a quick preview of the litedown site (I'll delete it later), and the example worked fine: https://git.yihui.org/tinyplot/manual.html#sec:examples_5:~:text=p()-,%23%20Themes%20showcase,-%23%23%20We%27ll%20use%20a |
In the example of the original post yes, but not in the simplified example I added later. |
Thanks everyone for diving deep on this. I really appreciate it. Just a HU that I'm going to be on vacation (and very likely off grid) for the next week. So I won't be very responsive for the next few days... but hopefully @vincentarelbundock or @zeileis can reply if anything important on the |
Thanks @grantmcdermott . I am currently trying to understand the difference with base plot system, and a minimal reproducible example in r-lib/evaluate#237 so that we can understand what is really going on and if this is at the evaluate level or not. Any help appreciated |
Hi @yihui,
I'm the maintainer of tinyplot, a lightweight extension of the base R graphics system. One of the extensions that we have introduced is compatible themes for convenient aesthetic styling. The help documentation provides various examples. including this final command to cycle through the available themes:
(Source code is here.)
This approach works as expected when running the examples in the console. Unfortunately, the rendered package website only displays the very final theme; see https://grantmcdermott.com/tinyplot/man/tinytheme.html#examples
Having stepped through the various rendering steps, I'm weakly confident that this is ultimately a
knitr
issue (rather than, say, aroxygen2
orquarto
issue). I have read through some older issues like #408, but they don't quite address my problem.Do you perhaps have any suggestions for how to ensure that all the plots in this example render in the knitted website?
Many thanks in advance and also for the many excellent R packages that you maintain.
The text was updated successfully, but these errors were encountered: