feat: Rework view()
to better work with RStudio and Positron
#1603
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #1551 (while I was here, I may as well...)
In RStudio and Positron, when
View(foo)
is called, we check iffoo
exists as a symbol bound in the parent environment. If it does, we can "track" the lifetime of that object and auto update the data viewer when the user makes changes to it. This doesn't work withview()
Screen.Recording.2024-09-30.at.10.56.25.AM.mov
This is because in
view()
we were actually inlining the whole data frame object, rather than the expression the user typed in. So RStudio and Positron can't find anything to "track". This was also causing issues in Positron too actually (the inlined data frame could overwhelm us) posit-dev/positron#4702.@lionel- and I thought about this a bit and came up with an approach where we capture the user input to
view()
and use that to reconstruct an equivalent call toView()
that we call in the parent environment. This mimics the idea of the user callingView(foo)
directly in the global environment, so that RStudio/Positron can "track"foo
correctly.x
isn't a data frame, we don't do any of this. We "make"x
into a data frame ourselves, so RStudio and Positron won't have anything to "track" in these cases so we don't do anything specialx
is a data frame but comes from something likeview(cbind(foo, foo))
, we do the fancy thing to recall this asView()
in the parent frame, which works fine, but of course RStudio and Positron still won't have anything to track because this is an ephemeral object. This is expected.It works like this now:
Screen.Recording.2024-09-30.at.10.54.40.AM.mov
Screen.Recording.2024-09-30.at.10.55.18.AM.mov
Side note, how do you add news bullets in tibble?