tidyverse / tibble

A modern re-imagining of the data frame
https://tibble.tidyverse.org/
Other
671 stars 130 forks source link

Enable `view()` to work better with how RStudio and Positron "track" objects #1602

Closed DavisVaughan closed 2 weeks ago

DavisVaughan commented 2 weeks ago

Closes https://github.com/tidyverse/tibble/issues/1551 (while I was here, I may as well...)

In RStudio and Positron, when View(foo) is called, we check if foo 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 with view()

https://github.com/user-attachments/assets/b2c7d809-2bc3-400e-8b14-5b93ed0b9aa7

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) https://github.com/posit-dev/positron/issues/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 to View() that we call in the parent environment. This mimics the idea of the user calling View(foo) directly in the global environment, so that RStudio/Positron can "track" foo correctly.

DavisVaughan commented 2 weeks ago

Woops meant to be a PR