The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.

Usage

# Example function to cached
fib <- function(n) {
 
    # Handle "vectors" by element
    if (length(n) > 1) {
        return(sapply(n, fib))
    }
 
    # Base cases
    if (n == 0) 
        return(0)
    if (n == 1) 
        return(1)
 
    # Check to see if n is an integer Do not use is.integer as that is very
    # strict
    if (round(n, 0) != n) 
        return(NA)
 
    # Negative numbers
    if (n < 0) 
        return(fib(-1 * n) * ((-1)^((n + 1)%%2)))
 
    # Everything else
    return(fib(n - 1) + fib(n - 2))
}

library(simpleRCache)

setCacheRootPath()

fibCached <- addMemoization(fib)

nums <- -25:25
 
system.time(fibResults <- fib(nums))
##    user  system elapsed 
##   1.128   0.032   1.220
system.time(fibResults1 <- fibCached(nums))
## DEBUG: Cache not saved
##    user  system elapsed 
##   1.005   0.013   1.119
# Second run should be cached
system.time(fibResults2 <- fibCached(nums))
##    user  system elapsed 
##   0.000   0.001   0.001
identical(fibResults, fibResults2)
## [1] TRUE
identical(fibResults1, fibResults2)
## [1] TRUE

Session Info

sessionInfo()

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.