r-lib / memoise

Easy memoisation for R
https://memoise.r-lib.org
Other
317 stars 59 forks source link

Override `View()` to support memoised functions #140

Open wurli opened 2 years ago

wurli commented 2 years ago

In RStudio, calling View() on a memoised function does not take you to the original function's source. On the one hand this makes it very clear to the user that their function is doing special stuff; on the other it can be a pain during development. This behaviour could be changed, e.g. as follows:

View <- function(x, title) {
  if (memoise::is.memoised(x)) {
    x <- environment(x)[["_f"]]
  }
  eval(substitute(
    get("View", envir = as.environment("package:utils"))(x, title)
  ))
}
wurli commented 1 year ago

NB, tibble::view() is an enhanced version of View() for dataframes.