forked from wadpac/GGIR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepareNewRelease.R
99 lines (99 loc) · 3.41 KB
/
prepareNewRelease.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
prepareNewRelease = function(version = c()) {
# In preparation of a new package release this function helps
# to check that version number and release date are correct
# in the DESCRIPTION file, GGIR-package.Rd, CITATION.cff, and NEWS.Rd
# The function does not fix any errors, it only warns the user about
# mistakes via messages in the console.
# The function is not part of the package on CRAN, because it's name is
# listed in the .RBuildignore file.
# Argument version: a character specifying the expected version number, e.g. "1.8-1"
date = unlist(strsplit(as.character(Sys.time())," "))[1]
dateReversed = unlist(strsplit(date,"-"))
dateReversed = paste0(dateReversed[3],"-",dateReversed[2],"-",dateReversed[1])
# Check DESCRIPTION file
D = read.csv(file = "./DESCRIPTION",sep="\n")
errorfound = FALSE
i = 1
while (i <= nrow(D)) {
tmp = as.character(unlist(strsplit(as.character(D[i,]),": ")))
if (tmp[1] == "Version") {
if (tmp[2] != version) {
cat("\nError: Version number is not correct in DESCRIPTION file")
errorfound = TRUE
}
}
if (tmp[1] == "Date") {
if (tmp[2] != date) {
cat("\nError: Date is not correct in DESCRIPTION file")
errorfound = TRUE
}
}
i = i + 1
}
# Check GGIR-package.Rd file
P = read.csv(file = "./man/GGIR-package.Rd",sep="\n")
i = 1
while (i <= nrow(P)) {
tmp = as.character(unlist(strsplit(as.character(P[i,]),"[: \\]")))
if (tmp[1] == "Version") {
if (tmp[5] != version) {
cat("\nError: Version number is not correct in GGIR-package.Rd file")
errorfound = TRUE
}
}
if (tmp[1] == "Date") {
if (tmp[5] != date) {
cat("\nError: Date is not correct in GGIR-package.Rd file")
errorfound = TRUE
}
}
i = i + 1
}
# Check CITATION.cff
CIT = read.csv(file = "./CITATION.cff",sep="\n")
i = 1
while (i <= nrow(CIT)) {
tmp = as.character(unlist(strsplit(as.character(CIT[i,]),": ")))
if (tmp[1] == "version") {
if (tmp[2] != version) {
cat("\nError: Version number is not correct in CITATION.cff file")
errorfound = TRUE
}
}
if (tmp[1] == "date-released") {
if (tmp[2] != date) {
cat("\nError: Date is not correct in CITATION.cff file")
errorfound = TRUE
}
}
i = i + 1
}
# Check NEWs.rd file
NE = read.csv(file = "./inst/NEWS.Rd",sep="\n")
i = 1
versioninfile = dateinfile = c()
while (i <= nrow(NE)) {
tmp = as.character(unlist(strsplit(as.character(NE[3,]),"version ")))
if (length(tmp) > 1) {
tmp2 = as.character(unlist(strsplit(as.character(tmp[2])," ")))
versioninfile= tmp2[1]
if (length(tmp2) > 2) {
tmp3 = as.character(unlist(strsplit(as.character(tmp2[3]),":"))[2])
dateinfile = as.character(unlist(strsplit(as.character(tmp3),"[)]"))[1])
}
}
if (length(versioninfile) > 0 & length(dateinfile) > 0) {
if (versioninfile != version) {
cat("\nError: Version number is not correct in NEWS.Rd file")
errorfound = TRUE
}
if (dateinfile != dateReversed) {
cat("\nError: Date is not correct in NEWS.Rd file")
errorfound = TRUE
}
break() # only check first date and version number
}
i = i + 1
}
if (errorfound == FALSE) cat(paste0("\nNo problem found. Package consistently uses version ",version," and date ", dateReversed))
}