i.e.
view <- function(x) {
if (interactive()) {
View(x)
}
invisible(x)
}
Advantages over View():
Consider making it a generic
"Does nothing when not in an interactive context" will be very useful to avoid issues when it's (mistakenly) used in an R Markdown document
Echo on making it a generic, that way we can get it to work on tbl_sql objects, where we can collect() the top 1,000 records and have it open a data viewer, unlike the list viewer that it opens today if I don't perform collect() first.
Should this live in tibble?
I'm not sure - on one hand it seems better because tibble is a lower-level package; but on the other tibble, generally doesn't provide generic verbs.
We do have print() and glimpse() in tibble, so view() seems like a good fit.
Well, print() lives in base, but glimpse() is a compelling argument. Let's move this to tibble.
Closing in favor of https://github.com/tidyverse/tibble/issues/373.
Most helpful comment
"Does nothing when not in an interactive context" will be very useful to avoid issues when it's (mistakenly) used in an R Markdown document