Fix db_get_zoom() to support zooming on empty tables #628
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 #626
This is a small fix for a very interesting error!
In fact the error we see in linked issue is not one, it's just a message, and it's sent by RStudio, not base R.
Here's a minimal reproduction of the issue :
As we see, the
foo
object was properly created and modified, but the fact that the length method fails makes RStudio display the problematic message.The guilty function is
.rs.describeObject
, it seems to be called after an object is created or modified in the console, and it callslength()
.In our case we have
length()
-->length.zoomed_dm()
-->tbl_zoomed()
-->dm_get_zoom()
, anddm_get_zoom(our_zoomed_dm)
fails throughabort_not_pulling_multiple_zoomed()
Our code didn't call
length()
on our object, so the bug is not our fault butRstudio's, however this showed us that our length method has a problem since
a zoomed dm containing an empty table is legal but its length isn't.
The idiom
lengths(zoom) != 0
was used to filter the zoomed rows, likely expecting zero length elements to beNULL
, butlength(tibble())
has length zero too. We use!map_lgl(zoom, is.null)
instead and the issue disappears.I opened a RStudio issue too : rstudio/rstudio#9887