vctrs icon indicating copy to clipboard operation
vctrs copied to clipboard

make vec_restore(<AsIs>) apply AsIs to the restored object, not its proxy

Open mjskay opened this issue 8 months ago • 1 comments

I ran into a weird ggplot2 bug when using I(...) with some aesthetics that I eventually traced back to a bug in the implementation of vec_restore.AsIs(). It currently applies the "AsIs" class to the proxy of the wrapped type without actually restoring the underlying type. I believe this is a simple fix.

Before:

x = posterior::rvar(1)

vctrs::vec_slice(x, 1)
#> rvar<1>[1] mean ± sd:
#> [1] 1 ± NA

vctrs::vec_slice(I(x), 1)
#> [[1]]
#> [[1]]$index
#> [1] 1
#> 
#> [[1]]$nchains
#> [1] 1
#> 
#> [[1]]$draws
#>   [,1]
#> 1    1

Created on 2023-12-21 with reprex v2.0.2

After:

x = posterior::rvar(1)

vctrs::vec_slice(x, 1)
#> rvar<1>[1] mean ± sd:
#> [1] 1 ± NA

vctrs::vec_slice(I(x), 1)
#> rvar<1>[1] mean ± sd:
#> [1] 1 ± NA

Created on 2023-12-21 with reprex v2.0.2

mjskay avatar Dec 21 '23 06:12 mjskay