Skip to content

Commit a882c8c

Browse files
author
hornik
committed
Have R CMD build add R >= 4.1.0 dependency when using pipe or function
shorthand in package code files. Based on R-devel post by Ivan Krylov. git-svn-id: https://svn.r-project.org/R/trunk@87613 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 342369e commit a882c8c

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/library/tools/R/build.R

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,11 +1165,13 @@ inRbuildignore <- function(files, pkgdir) {
11651165
desc <- .read_description(file.path(pkgname, "DESCRIPTION"))
11661166
Rdeps <- .split_description(desc)$Rdepends2
11671167
hasDep350 <- FALSE
1168+
hasDep410 <- FALSE
11681169
for(dep in Rdeps) {
11691170
if(dep$op != '>=') next
11701171
if(dep$version >= "3.5.0") hasDep350 <- TRUE
1172+
if(dep$version >= "4.1.0") hasDep410 <- TRUE
11711173
}
1172-
if (!hasDep350) {
1174+
if(!hasDep350) {
11731175
## re-read files after exclusions have been applied
11741176
allfiles <- dir(".", all.files = TRUE, recursive = TRUE,
11751177
full.names = TRUE)
@@ -1180,15 +1182,29 @@ inRbuildignore <- function(files, pkgdir) {
11801182
fixup_R_dep(pkgname, "3.5.0")
11811183
msg <- paste("WARNING: Added dependency on R >= 3.5.0 because",
11821184
"serialized objects in serialize/load version 3",
1183-
"cannot be read in older versions of R. File(s)",
1184-
"containing such objects:")
1185+
"cannot be read in older versions of R.")
11851186
printLog(Log,
11861187
paste(c(strwrap(msg, indent = 2L, exdent = 2L),
1188+
" File(s) containing such objects:",
11871189
paste0(" ", .pretty_format(sort(toonew)))),
11881190
collapse = "\n"),
11891191
"\n")
11901192
}
11911193
}
1194+
if(!hasDep410) {
1195+
files <- names(.package_code_using_R_4.1_syntax(pkgname))
1196+
if(length(files)) {
1197+
fixup_R_dep(pkgname, "4.1.0")
1198+
msg <- paste("WARNING: Added dependency on R >= 4.1.0 because",
1199+
"package code uses the pipe |> or function shorthand \\(...) syntax added in R 4.1.0.")
1200+
printLog(Log,
1201+
paste(c(strwrap(msg, indent = 2L, exdent = 2L),
1202+
" File(s) using such syntax:",
1203+
paste0(" ", .pretty_format(sort(files)))),
1204+
collapse = "\n"),
1205+
"\n")
1206+
}
1207+
}
11921208

11931209
## add NAMESPACE if the author didn't write one
11941210
if(!file.exists(namespace <- file.path(pkgname, "NAMESPACE")) ) {

0 commit comments

Comments
 (0)