-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathprecran.R
More file actions
137 lines (120 loc) · 4.75 KB
/
precran.R
File metadata and controls
137 lines (120 loc) · 4.75 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
# precran.R — Run typical pre-CRAN checks
# Usage from the package root:
# Rscript precran.R
# or source("precran.R") from an interactive session.
message("==== Pre-CRAN preflight starting ====")
# 1) Ensure required helper packages are available
required <- c(
"devtools", # document, build, check, win-builder helpers
"rcmdcheck", # programmatic R CMD check
"spelling", # spell-check Rd, vignettes, R
"urlchecker", # validate and fix URLs in Rd, R, vignettes
"lintr", # static code analysis
"styler", # code style checks
"desc", # DESCRIPTION helpers
"rhub" # R-hub v2 remote checks (Windows/Linux)
)
missing <- setdiff(required, rownames(installed.packages()))
if (length(missing)) {
message("Installing missing packages: ", paste(missing, collapse = ", "))
install.packages(missing, repos = "https://cloud.r-project.org")
}
suppressPackageStartupMessages({
lapply(required, requireNamespace, quietly = TRUE, character.only = TRUE)
})
# 2) Basic metadata sanity checks
message("\n==> Checking DESCRIPTION sanity")
d <- desc::desc(file = "DESCRIPTION")
fields_needed <- c("Package", "Version", "Title", "Description", "License")
missing_fields <- fields_needed[!fields_needed %in% d$fields()]
if (length(missing_fields)) {
stop("Missing DESCRIPTION fields: ", paste(missing_fields, collapse = ", "))
}
if (grepl("TODO|TBD|FILL ME|FIXME", d$get("Description"))) {
stop("DESCRIPTION 'Description' contains placeholders. Please fix.")
}
message("DESCRIPTION looks OK")
# 3) Regenerate docs and namespace
message("\n==> Generating Rd files and NAMESPACE via roxygen2")
devtools::document(quiet = TRUE)
# # 4) Optional: build README if a README.Rmd exists
# if (file.exists("README.Rmd")) {
# message("\n==> Building README")
# try(devtools::build_readme(), silent = TRUE)
# }
# 5) NEWS and CRAN-RELEASE presence check (non-fatal)
if (!file.exists("NEWS.md")) message("Note: Consider maintaining a NEWS.md")
if (!file.exists("CRAN-SUBMISSION") && !file.exists("CRAN-RELEASE")) {
message("Note: Consider using usethis::use_cran_comments() and keeping CRAN comments/notes")
}
# 6) URL checks
message("\n==> Checking URLs")
bad <- urlchecker::url_check()
if (nrow(bad)) {
print(bad)
message("You can try: urlchecker::url_update() to auto-fix redirects.")
} else {
message("All URLs OK")
}
# 7) Spell check
message("\n==> Spell checking package")
sp <- spelling::spell_check_package()
if (nrow(sp)) {
print(sp[, c("file", "line", "word")])
message("Add accepted words to inst/WORDLIST or fix typos.")
} else {
message("No spelling issues found")
}
# 8) Lint R code
message("\n==> Linting R code")
lint_res <- lintr::lint_package()
if (length(lint_res)) {
print(lint_res)
message("Consider running styler::style_pkg() or address lintr suggestions.")
} else {
message("No lints found")
}
# 9) Local CRAN-style check
message("\n==> Local R CMD check --as-cran")
# rcmdcheck returns an object with summaries; devtools::check() opens viewer; prefer rcmdcheck here
chk <- rcmdcheck::rcmdcheck(args = c("--as-cran"), error_on = "never", build_args = "--no-manual")
summary <- rcmdcheck::parse_check(chk$results)
print(chk)
if (length(chk$errors)) message("Errors: ", length(chk$errors))
if (length(chk$warnings)) message("Warnings: ", length(chk$warnings))
if (length(chk$notes)) message("Notes: ", length(chk$notes))
# 10) Build source tarball
message("\n==> Building source tarball")
pkgfile <- devtools::build(path = "dist", quiet = TRUE)
message("Built: ", pkgfile)
# 11) Remote checks with R-hub v2 (Windows + Linux)
message("\n==> R-hub v2 checks (Windows + Linux)")
# Requires a GitHub repo or local setup; see ?rhubv2
# If your package is on GitHub, set gh_url to your repo. Otherwise, rhub will infer from current git remote.
# Common platforms include: 'windows-x86_64-release', 'ubuntu-gcc-release'.
# Use rhub::rhub_check() with defaults or specify platforms explicitly.
try({
#p <- rhub::rhub_platforms()
rhub::rhub_check(platforms = "ubuntu-latest (r-release)")
# pick <- function(rx) {
# x <- p$name[grepl(rx, p$name, ignore.case = TRUE)]
# if (length(x)) x[1] else character(0)
# }
#
# plats <- unique(c(
# pick("^ubuntu.*r-release"),
# pick("^macos.*r-release"),
# pick("^windows.*r-release")
# ))
#
# print(plats) # sanity check; should be non-empty exact names
# rhub::rhub_check(platforms = plats)
}, silent = TRUE)
# 12) Optional: Win-builder checks via devtools
message("\n==> Optional: win-builder checks")
message("Skip with options(precran.skip_winbuilder = TRUE) to bypass")
if (!isTRUE(getOption("precran.skip_winbuilder", FALSE))) {
try(devtools::check_win_release(), silent = TRUE)
try(devtools::check_win_devel(), silent = TRUE)
}
message("\n==== Pre-CRAN preflight complete ====")