-
Notifications
You must be signed in to change notification settings - Fork 26
/
copy_Rout_to_Routsave.R
106 lines (84 loc) · 3.54 KB
/
copy_Rout_to_Routsave.R
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
################################################################################
#
# USE THIS SCRIPT TO REPLACE ALL OCCURENCES OF *.Rout.save WITH NEW *.Rout FILES
#
# Author: Benjamin Hofner, 2012
#
# USAGE:
# ## To copy test output
# Rscript copy_Rout_to_Routsave.R "vignettes=FALSE"
# ## To copy vignette output
# Rscript copy_Rout_to_Routsave.R "vignettes=TRUE"
#
# ALTERNATIVE USAGE (with R CMD BATCH):
# ## To copy test output
# R CMD BATCH "--args vignettes=FALSE" copy_Rout_to_Routsave.R
# ## To copy vignette output
# R CMD BATCH "--args vignettes=TRUE" copy_Rout_to_Routsave.R
#
################################################################################
## Get command line arguments
args <- commandArgs(TRUE)
if (length(args) > 1)
stop("specify (at maximum) one arguments (i.e., vignettes)")
eval(parse(text=args))
if (length(args) == 0) {
vignettes <- FALSE
path <- "."
check_path <- "../mboost.Rcheck/"
################################################################################
## Copy output of test files
if (vignettes == FALSE) {
## Get relevant file names
ROUT <- list.files(path = check_path, pattern = ".Rout$", recursive = TRUE)
ROUT <- ROUT[!grepl("testthat", ROUT)]
ROUT <- ROUT[!grepl("386", ROUT)]
ROUT2 <- paste(check_path, ROUT, sep ="")
ROUT <- gsub("_x64", "", ROUT)
ROUT.SAVE <- list.files(path = path, pattern = ".Rout.save$", recursive = TRUE)
ROUT.SAVE <- paste(path, "/", ROUT.SAVE, sep ="")
ROUT.SAVE <- ROUT.SAVE[grep("test", ROUT.SAVE)]
## sort ROUT.SAVE
idx <- rep(NA, length(ROUT))
for (i in 1:length(ROUT))
idx[i] <- grep(ROUT[i], ROUT.SAVE)
ROUT.SAVE <- ROUT.SAVE[idx]
cbind(ROUT2, ROUT.SAVE)
cat("\n\nCopy *.Rout to *.Rout.save:\n---------------------------\n")
for (i in 1:length(ROUT))
print(file.copy(ROUT2[i], ROUT.SAVE[i], overwrite = TRUE))
cat("#########################################################################",
"# To revert changes simply use:",
"# git checkout -- tests",
"#########################################################################",
sep = "\n")
}
################################################################################
## Copy output of vignettes
if (vignettes == TRUE) {
vpath <- paste(path, "vignettes", sep ="/")
## get vignette output as created by R CMD check:
vROUT <- list.files(path = check_path, pattern = ".Rnw.log$")
if (length(vROUT) > 0) {
vROUT2 <- paste(check_path, vROUT, sep ="")
vROUT.SAVE <- list.files(path = vpath, pattern = ".Rout.save",
recursive = TRUE)
vROUT.SAVE <- paste(vpath, vROUT.SAVE, sep = "/")
## sort
filenames <- gsub("(.*)\\.Rnw\\.log", "\\1", vROUT)
idx <- sapply(filenames, function(fn)
res <- grep(paste(fn, "\\.Rout\\.save$", sep=""), vROUT.SAVE))
vROUT.SAVE <- vROUT.SAVE[idx]
cbind(vROUT2, vROUT.SAVE)
cat("\n\nCopy *.Rnw.log to *.Rout.save:\n---------------------------\n")
for (i in 1:length(vROUT))
print(file.copy(vROUT2[i], vROUT.SAVE[i], overwrite = TRUE))
cat("#########################################################################",
"# To revert changes simply use:",
"# git checkout -- vignettes",
"#########################################################################",
sep = "\n")
} else {
cat("\n\nNOTE: No changes in output of vignettes.\n\n")
}
}