1

I'm frequently use Rstudio's "Go To Function Definition" (shortcut is F2) in order to navigate between many files and quickly access a function's definition / make changes (printing the function's definition is usually not enough).

In order to make my analysis quicker, many of my functions are memoised with the package 'memoise'. This is all and well, but when I use the "Go To Function Definition" button (or F2), it takes me to the memoise function. This is the result:

function (Date = Sys.Date(), Symbol) 
{
  hash <- `_digest`(c(list(Date, Symbol), lapply(`_additional`, 
    function(x) eval(x[[2L]], environment(x)))), algo = "sha512")
  if (`_cache`$has_key(hash)) {
    res <- `_cache`$get(hash)
  }
  else {
    res <- withVisible(`_f`(Date = Date, Symbol = Symbol))
    `_cache`$set(hash, res)
  }
  if (res$visible) {
    res$value
  }
  else {
    invisible(res$value)
  }
}

One note - I tried defining the function and giving it its memoisation below it as follows: foo <- function(x) { return(x) } foo <- memoise::memoise(foo)

But when I run this on linux, any time I call foo I get an infinite loop. Oddly, it works well on Windows (and the F2 function works on windows with this method!). I need something that will work on a linux system as well as having F2 functionality work.

  • The `memoise()` function takes a function as input and returns a new function. There are plenty of functions that do this; memoise isn't that special. But given that, it would be hard for any IDE to go backwards through a function definition to get back to what you believe the "true" function to be. I don't see how this could work in the general case (unless you are expecting some very special code just to accommodate the memoise package). – MrFlick Aug 08 '18 at 21:31

0 Answers0