tidyverse / tibble

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

feat: Rework `view()` to better work with RStudio and Positron #1603

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.

It works like this now:

https://github.com/user-attachments/assets/a9415a07-717d-4600-b6b0-0457db5e8f72

https://github.com/user-attachments/assets/18890dcf-fa79-411c-95ec-0c717fc06283


Side note, how do you add news bullets in tibble?

krlmlr commented 2 weeks ago

Thanks! Happy to release as needed.