-
Notifications
You must be signed in to change notification settings - Fork 35
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
Plots in for loop #237
Comments
Simpler reprex? res <- evaluate::evaluate(function(){
for (i in 1:2) {
plot(1)
}
})
sapply(res, class)
#> [1] "source" "recordedplot" Created on 2025-02-06 with reprex v2.1.0 |
Although if I run that directly in the console, I see:
But I don't see that with tinyplot, which suggests that it's doing something different to |
It's the opposite for me:
|
Looks like
reprex::reprex({
library(tinyplot)
for (thm in 1:2) {
tinyplot(Sepal.Length ~ Petal.Length, data = iris)
}
}) prints 2 plots.
reprex::reprex({
library(tinyplot)
tinytheme("default")
for (thm in 1:2) {
tinyplot(Sepal.Length ~ Petal.Length, data = iris)
}
}) prints 1 plot. What I don't understand is that reprex::reprex({
for (thm in 1:2) {
plot(Sepal.Length ~ Petal.Length, data = iris)
}
}) also prints a single plot. I can't help further but hopefully that's useful to you. |
If the exact same plot is drawn, then it won't be recorded. Lines 46 to 74 in 9b41223
So what does I tried changing res <- evaluate::evaluate(function() {
for (bg in c("red", "blue")) {
par(bg = bg)
plot(Sepal.Length ~ Petal.Length, data = iris)
}
})
sapply(res, class)
#> [1] "source" "recordedplot" "recordedplot" While changing theme for tinyplot does return one res <- evaluate::evaluate(function(){
library(tinyplot)
for (thm in c("dark", "minimal")) {
tinytheme(thm)
tinyplot(I(Sepal.Length * 1e4) ~ Petal.Length | Species, data = iris)
}
})
sapply(res, class)
#> [1] "source" "source" "recordedplot" |
I don't know enough about graphics in base R (I'm not the author of Also, the This gives two plots: reprex::reprex({
for (i in 1:2) {
plot(i)
}
}) This gives one plot: reprex::reprex({
tinyplot::tinytheme("basic")
for (i in 1:2) {
plot(i)
}
}) |
Opening this issue to follow up on knitr report:
and as a way to keep track of this example. However, possibly related to
Plots in for loop are not treated the same as plots outside of it.
Not sure if something can be done around that, but this is now definitely a differentiating approach with how
litedown::fuse()
handles plot. So I would like to dig into this.The text was updated successfully, but these errors were encountered: