forked from boost-R/gamboostLSS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy_Rout_to_Routsave.R
116 lines (92 loc) · 3.76 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
107
108
109
110
111
112
113
114
115
116
################################################################################
#
# USE THIS SCRIPT TO REPLACE ALL OCCURENCES OF *.Rout.save WITH NEW *.Rout FILES
#
# Author: Benjamin Hofner, 2013
#
# USAGE:
# Use
# ## To copy test output
# Rscript copy_Rout_to_Routsave.R "path='pkg'" "vignettes=FALSE"
# ## To copy vignette output
# Rscript copy_Rout_to_Routsave.R "path='pkg'" "vignettes=TRUE"
#
# or use
# ## To copy test output
# Rscript copy_Rout_to_Routsave.R "path='patch'" "vignettes=FALSE"
# ## To copy vignette output
# Rscript copy_Rout_to_Routsave.R "path='patch'" "vignettes=TRUE"
#
################################################################################
## Get command line arguments
args <- commandArgs(TRUE)
if (length(args) > 2)
stop("specify (at maximum) two arguments (i.e., which and vignettes)")
eval(parse(text=args))
if (length(args) == 0) {
vignettes <- FALSE
path <- "pkg"
}
if (is.null(path))
path <- "pkg"
if (is.null(vignettes))
vignettes <- FALSE
which <- "gamboostLSS"
check_path <- "gamboostLSS.Rcheck/"
################################################################################
## Copy output of test files
if (vignettes == FALSE) {
## Get relevant file names
ROUT <- list.files(path = check_path, pattern = ".Rout$", recursive = TRUE)
ROUT2 <- paste(check_path, ROUT, sep ="")
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:",
ifelse(path == "pkg",
"# git checkout -- pkg/tests",
"# git checkout -- patch/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:",
ifelse(path == "pkg",
"# git checkout -- pkg/vignettes",
"# git checkout -- patch/vignettes"),
"#########################################################################",
sep = "\n")
} else {
cat("\n\nNOTE: No changes in output of vignettes.\n\n")
}
}