forked from bcaffo/courses
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindenting.R
More file actions
30 lines (27 loc) · 872 Bytes
/
Copy pathindenting.R
File metadata and controls
30 lines (27 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
cc <- function(expr, cachedir = ".cache", srcfile = NULL, ...) {
if(!identical(globalenv(), parent.frame()))
stop("'cc' must be called from the global environment")
subexpr <- substitute(expr)
exprtext <- deparse(subexpr, width.cutoff = 60)
if(is.null(srcfile))
srcfile <- file.path(tempdir(), hash(exprtext))
writeLines(exprtext, srcfile)
cacher(srcfile, cachedir, ...)
}
createLogFile <- function(cachedir, logfile, srcfile) {
if(is.null(logfile)) {
logfile <- file.path(logdir(cachedir),
paste(basename(srcfile), "log", sep="."))
file.create(logfile)
}
else if(is.na(logfile))
logfile <- stderr()
else
file.create(logfile)
setConfig("logfile", logfile)
}
identicalFiles <- function(x, y) {
## Are the contents of the two files the same?
checksum <- c(hashFile(x), hashFile(y))
identical(checksum[1], checksum[2])
}