Skip to content

Commit c1f3d14

Browse files
committed
Fix line endings
Change local line endings to LF and add .gitattributes.
1 parent e5c67ee commit c1f3d14

File tree

2 files changed

+59
-44
lines changed

2 files changed

+59
-44
lines changed

.gitattributes

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Set the default behavior, in case people don't have core.autocrlf set.
2+
* text=auto
3+
4+
# Explicitly declare text files you want to always be normalized and converted
5+
# to native line endings on checkout.
6+
*.R text
7+
*.Rmd text
8+
9+
# Declare files that will always have CRLF line endings on checkout.
10+
#*.sln text eol=crlf
11+
12+
# Denote all files that are truly binary and should not be modified.
13+
*.png binary
14+
*.jpg binary
15+
*.pdf binary

cachematrix.R

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
1-
#'This module contains two functions which aid in caching the inverse of a matrix.
2-
#' \code makeCacheMatrix returns an object which can hold a cache.
3-
#' \code cachesolve is used to compute or retrieve the inverse.
4-
5-
#' Create an object that contains a matrix and possibly a cached value of the inverse
6-
#' of the matrix.
7-
#'
8-
#' @param x the matrix to be contained and inverted
9-
#' @return a list containg the given matrix with functions to get, set the matrix and its inverse
10-
#' @seealso \code cacheSolve which actually computes the inverse and caches it
11-
makeCacheMatrix <- function(x = matrix()) {
12-
inverse <- NULL
13-
set <- function(y) {
14-
x <<- y
15-
m <<- NULL
16-
}
17-
get <- function() x
18-
setinverse <- function(inv) inverse <<-inv
19-
getinverse <- function() inverse
20-
list(set = set, get = get,
21-
setinverse = setinverse,
22-
getinverse = getinverse)
23-
}
24-
25-
26-
#' Compute or retrieve the inverse of a matrix
27-
#'
28-
#' @param x an object created by \code makeCacheMatrix
29-
#' @return the inverse of x
30-
#' Assumes that x is invertible, otherwise will cause an error. The matrix
31-
#' inverse is retrieved from x if a cached value is available, otherwise
32-
#' the inverse is computed and cached.
33-
cacheSolve <- function(x, ...) {
34-
i <- x$getinverse()
35-
if(!is.null(i)) {
36-
message("getting cached data")
37-
return(i)
38-
}
39-
data <- x$get()
40-
i <- solve(data, ...)
41-
x$setinverse(i)
42-
i
43-
44-
}
1+
#'This module contains two functions which aid in caching the inverse of a matrix.
2+
#' \code makeCacheMatrix returns an object which can hold a cache.
3+
#' \code cachesolve is used to compute or retrieve the inverse.
4+
5+
#' Create an object that contains a matrix and possibly a cached value of the inverse
6+
#' of the matrix.
7+
#'
8+
#' @param x the matrix to be contained and inverted
9+
#' @return a list containg the given matrix with functions to get, set the matrix and its inverse
10+
#' @seealso \code cacheSolve which actually computes the inverse and caches it
11+
makeCacheMatrix <- function(x = matrix()) {
12+
inverse <- NULL
13+
set <- function(y) {
14+
x <<- y
15+
m <<- NULL
16+
}
17+
get <- function() x
18+
setinverse <- function(inv) inverse <<-inv
19+
getinverse <- function() inverse
20+
list(set = set, get = get,
21+
setinverse = setinverse,
22+
getinverse = getinverse)
23+
}
24+
25+
26+
#' Compute or retrieve the inverse of a matrix
27+
#'
28+
#' @param x an object created by \code makeCacheMatrix
29+
#' @return the inverse of x
30+
#' Assumes that x is invertible, otherwise will cause an error. The matrix
31+
#' inverse is retrieved from x if a cached value is available, otherwise
32+
#' the inverse is computed and cached.
33+
cacheSolve <- function(x, ...) {
34+
i <- x$getinverse()
35+
if(!is.null(i)) {
36+
message("getting cached data")
37+
return(i)
38+
}
39+
data <- x$get()
40+
i <- solve(data, ...)
41+
x$setinverse(i)
42+
i
43+
44+
}

0 commit comments

Comments
 (0)