Skip to content

new evaluate does remove identical plot more aggressively #243

Open
@cderv

Description

@cderv

This was reported in

Previously, with 0.24.0, this would produce two recorded plot

ev <- evaluate::evaluate(function() {
     hist(cars$speed)
     hist(cars$speed, breaks = "Scott")
 })
 lapply(ev, class)
#> [[1]]
#> [1] "source"
#> 
#> [[2]]
#> [1] "recordedplot"
#> 
#> [[3]]
#> [1] "source"
#> 
#> [[4]]
#> [1] "recordedplot"
 packageVersion("evaluate")
#> [1] '0.24.0'

and knitr would be responsible to keep only one or all depending on fig.keep options

> md <- glue::glue("
```{r}
hist(cars$speed)
hist(cars$speed, breaks = 'Scott')
```
", .open = "{{", .close = "}}")
> knitr::knit(text = md) |> cat()
1/1 [unnamed-chunk-1]

``` r
hist(cars$speed)
hist(cars$speed, breaks = 'Scott')
```

![plot of chunk unnamed-chunk-1](figure/unnamed-chunk-1-1.png)

> knitr::opts_chunk$set(fig.keep="all")
> knitr::knit(text = md|> cat()
1/1 [unnamed-chunk-1]

``` r
hist(cars$speed)
```

![plot of chunk unnamed-chunk-1](figure/unnamed-chunk-1-1.png)

``` r
hist(cars$speed, breaks = 'Scott')
```

![plot of chunk unnamed-chunk-1](figure/unnamed-chunk-1-2.png)

However, with evaluate 1.0.0, there is now a new logic to detect different plots

evaluate::evaluate(function() {
     hist(cars$speed)
     hist(cars$speed, breaks = "Scott")
 })
#> <evaluation>
#> Source code: 
#>   hist(cars$speed)
#> Plot [7]:
#>   <base> C_plot_new()
#>   <base> palette2()
#>   <base> C_plot_window()
#>   <base> C_title()
#>   <base> C_axis()
#>   <base> C_axis()
#>   <base> C_rect()
#> Source code: 
#>   hist(cars$speed, breaks = "Scott")

So fig.keep = 'all' does not have the effect as there is no second plot to keep now.

Is this change expected?

Or could it be something to check when this was rewritten ?

evaluate/R/watchout.R

Lines 62 to 69 in 1c4492b

plot <- recordPlot()
if (!makes_visual_change(plot[[1]])) {
return()
}
if (!looks_different(last_plot[[1]], plot[[1]])) {
return()
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions