Skip to content

Commit 194cd08

Browse files
committed
Expression caching
1 parent b165aaa commit 194cd08

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

cachematrix.R

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@
44
# mci <- makeCacheMatrix(m, func = function(m){message("calculating");solve(m)})
55
# cacheSolve(mci)
66
# cacheSolve(mci) # should not print message again, should insted inform about cache use
7-
# mcs <- makeCacheMatrix(m, c(1,1))
7+
# mcs <- makeCacheMatrix(m, c(1,1), tol = .001)
88
# cacheSolve(mcs)
99

1010
# Class for creating matrices with
1111
# ability to cache results of operations
12+
# see CacheOps$help(getResult)
1213
CachedOps <- setRefClass("CachedOps",
1314
fields = list(func = "function", cache = "ANY"),
1415

1516
methods = list(
16-
initialize = function(...,func){
17+
initialize = function(expr,...){
1718
cache <<- NULL
1819
func <<- function(){
19-
func(...)
20+
expr
2021
}
2122
callSuper()
2223
},
@@ -31,15 +32,15 @@ Once it was calculated result is cached and returned in any consecutive call"
3132
})
3233
)
3334

34-
makeCacheMatrix <- function(..., func = solve) {
35+
makeCacheMatrix <- function(expr,...) {
3536
# Creating new caching object
3637
# Args:
3738
# func - function, result of calculation is need to cache
3839
# ... - parameters for function calling
39-
CachedOps$new(..., func = func)
40+
CachedOps$new(expr,...)
4041
}
4142

42-
cacheSolve <- function(x, ...) {
43+
cacheSolve <- function(x) {
4344
# Calculating result of function on matrix
4445
# once it was calculated result is cached
4546
# and returned in any consecutive call

0 commit comments

Comments
 (0)