r-lib / memoise

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

`View(memoised_function)` produces unhelpful results #150

Closed wurli closed 1 year ago

wurli commented 1 year ago

I often use View() in RStudio to navigate to a function's source code, but this doesn't produce anything helpful if the function in question is memoised. As a result I tend to overload View() like so:

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

I'd suggest including something like this in {memoise}, or perhaps mentioning the workaround in the documentation, as this can be an annoying inconvenience that I doubt many users will find a workaround for.

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

wurli commented 1 year ago

Closing as I forgot I already opened #140 for this exact problem 🤦