| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
checkCodeFiles <- function(fileName) { |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
retList <- list() |
| 37 |
|
| 38 |
|
| 39 |
ok <- x <- c() |
| 40 |
tmpRetEnv <- new.env() |
| 41 |
tmpRet <- NULL |
| 42 |
|
| 43 |
|
| 44 |
lsTmp <- lsInit <- ls() |
| 45 |
|
| 46 |
sapply(fileName, function(x) { |
| 47 |
cat("\n file ",x) |
| 48 |
|
| 49 |
ok <- try(utils::capture.output(source(x, local=TRUE, echo=FALSE))) |
| 50 |
if (inherits(ok, "try-error")) { |
| 51 |
cat("\n file",x,"could not be sourced:", geterrmessage(), "\n") |
| 52 |
return() |
| 53 |
} |
| 54 |
newElements <- setdiff(ls(), lsTmp) |
| 55 |
cat("\n functions",paste(newElements, collapse=", ")) |
| 56 |
lsTmp <- ls() |
| 57 |
sapply(newElements, function(x) { |
| 58 |
ok <- try(get(x)) |
| 59 |
if (!inherits(ok, "try-error") && identical(mode(ok), "function")) { |
| 60 |
cat("\n ",x," (",is(ok)[1],"): ",sep="") |
| 61 |
|
| 62 |
|
| 63 |
reportFunc <- function(x) { |
| 64 |
cat(x) |
| 65 |
assign("tmpRet", c(tmpRet, x), pos=parent.env(tmpRetEnv)) |
| 66 |
} |
| 67 |
codetools::checkUsage(ok, report=reportFunc, all=TRUE) |
| 68 |
|
| 69 |
if (!is.null(tmpRet)) { |
| 70 |
retList[[length(retList) + 1]] <<- tmpRet |
| 71 |
names(retList)[length(retList)] <<- x |
| 72 |
} |
| 73 |
tmpRet <<- NULL |
| 74 |
} |
| 75 |
}) |
| 76 |
}) |
| 77 |
|
| 78 |
return(invisible(retList)) |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
checkCodeFolders <- function(path=".") { |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
stopifnot(require(codetools)) |
| 97 |
if (!is(path, "character")) { |
| 98 |
stop("argument 'path' has to be of type 'character'.") |
| 99 |
} |
| 100 |
if (!all(file.exists(path))) { |
| 101 |
stop("argument 'path' has to contain existing folder(s).") |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
fNames <- list.files(path=path, pattern="\\.[rRsS]$", full.names=TRUE) |
| 106 |
|
| 107 |
checkCodeFiles(fNames) |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
checkCodeSweave <- function(path=".") { |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
stopifnot(require(utils)) |
| 134 |
stopifnot(require(codetools)) |
| 135 |
|
| 136 |
if (!is(path, "character")) { |
| 137 |
stop("argument 'path' has to be of type 'character'.") |
| 138 |
} |
| 139 |
if (!all(file.exists(path))) { |
| 140 |
stop("argument 'path' has to contain existing folder(s).") |
| 141 |
} |
| 142 |
browser() |
| 143 |
|
| 144 |
path <- path.expand(path) |
| 145 |
pwd <- getwd() |
| 146 |
if (length(path)) { |
| 147 |
if (path == ".") { |
| 148 |
path <- pwd |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
} |
| 153 |
|
| 154 |
fName <- list.files(path=path, pattern="\\.[RS]nw$", full.names=TRUE) |
| 155 |
|
| 156 |
timeStamp <- format(Sys.time(), "%y%m%d-%H%M") |
| 157 |
tmpDir <- file.path(tempdir(), timeStamp) |
| 158 |
print(tmpDir) |
| 159 |
if(!file.exists(tmpDir)) { |
| 160 |
stopifnot(dir.create(tmpDir, recursive=TRUE)) |
| 161 |
} |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
setwd(tmpDir) |
| 166 |
on.exit(setwd(pwd), add=TRUE) |
| 167 |
|
| 168 |
codeFiles <- unlist(sapply(fName, function(x) { |
| 169 |
Stangle(x) |
| 170 |
x <- basename(x) |
| 171 |
gsub("[RS]nw$", "R", x) |
| 172 |
})) |
| 173 |
|
| 174 |
|
| 175 |
codeFiles <- file.path(tmpDir, codeFiles) |
| 176 |
checkCodeFiles(codeFiles) |
| 177 |
} |