Skip to content
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

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mjskay
Copy link

@mjskay mjskay commented Dec 21, 2023

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
Copy link
Author

mjskay commented Dec 21, 2023

Ah, I also had to adjust the definition of asis_restore() to pass some tests --- it now prevents "AsIs" from being added multiple times. Although it's worth noting that its implementation is now exactly the same as I(), so it could perhaps be replaced with that function if desired.

mjskay added a commit to mjskay/vctrs that referenced this pull request Dec 21, 2023
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

Successfully merging this pull request may close these issues.

None yet

1 participant