Skip to content

Commit

Permalink
Have R CMD build add R >= 4.1.0 dependency when using pipe or function
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hornik committed Jan 22, 2025
1 parent 342369e commit a882c8c
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/library/tools/R/build.R
Original file line number Diff line number Diff line change
Expand Up @@ -1165,11 +1165,13 @@ inRbuildignore <- function(files, pkgdir) {
desc <- .read_description(file.path(pkgname, "DESCRIPTION"))
Rdeps <- .split_description(desc)$Rdepends2
hasDep350 <- FALSE
hasDep410 <- FALSE
for(dep in Rdeps) {
if(dep$op != '>=') next
if(dep$version >= "3.5.0") hasDep350 <- TRUE
if(dep$version >= "4.1.0") hasDep410 <- TRUE
}
if (!hasDep350) {
if(!hasDep350) {
## re-read files after exclusions have been applied
allfiles <- dir(".", all.files = TRUE, recursive = TRUE,
full.names = TRUE)
Expand All @@ -1180,15 +1182,29 @@ inRbuildignore <- function(files, pkgdir) {
fixup_R_dep(pkgname, "3.5.0")
msg <- paste("WARNING: Added dependency on R >= 3.5.0 because",
"serialized objects in serialize/load version 3",
"cannot be read in older versions of R. File(s)",
"containing such objects:")
"cannot be read in older versions of R.")
printLog(Log,
paste(c(strwrap(msg, indent = 2L, exdent = 2L),
" File(s) containing such objects:",
paste0(" ", .pretty_format(sort(toonew)))),
collapse = "\n"),
"\n")
}
}
if(!hasDep410) {
files <- names(.package_code_using_R_4.1_syntax(pkgname))
if(length(files)) {
fixup_R_dep(pkgname, "4.1.0")
msg <- paste("WARNING: Added dependency on R >= 4.1.0 because",
"package code uses the pipe |> or function shorthand \\(...) syntax added in R 4.1.0.")
printLog(Log,
paste(c(strwrap(msg, indent = 2L, exdent = 2L),
" File(s) using such syntax:",
paste0(" ", .pretty_format(sort(files)))),
collapse = "\n"),
"\n")
}
}

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

0 comments on commit a882c8c

Please sign in to comment.