forked from hofnerb/stabs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy_Rout_to_Routsave.R
124 lines (102 loc) · 4.23 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
117
118
119
120
121
122
123
124
################################################################################
#
# USE THIS SCRIPT TO REPLACE ALL OCCURENCES OF *.Rout.save WITH NEW *.Rout FILES
#
# Author: Benjamin Hofner, 2012-2014
#
# USAGE:
# Use either
# ## 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):
# Use either
# ## 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 argument (i.e., vignettes)")
eval(parse(text=args))
if (length(args) == 0) {
vignettes <- FALSE
}
if (is.null(vignettes))
vignettes <- FALSE
path <- "."
check_path <- "../stabs.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)
## remove new Routs from checks
#ROUT.SAVE <- ROUT.SAVE[!grepl(check_path, ROUT.SAVE)]
ROUT.SAVE <- paste(path, "/", ROUT.SAVE, sep ="")
ROUT.SAVE <- ROUT.SAVE[grep("test", ROUT.SAVE)]
if (length(ROUT.SAVE) == length(ROUT)) {
## 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")
} else {
which_missing <- !(ROUT %in% ROUT.SAVE)
ROUT <- paste0(path, "/", ROUT[which_missing], ".save")
file.create(ROUT)
## add to git
for (file in ROUT)
system(paste0("git add ", file))
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")
}
}