From a882c8c4d498e4b59fc32f023e48bc42484bca3a Mon Sep 17 00:00:00 2001 From: hornik Date: Wed, 22 Jan 2025 06:39:47 +0000 Subject: [PATCH] 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 --- src/library/tools/R/build.R | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/library/tools/R/build.R b/src/library/tools/R/build.R index 1548bf63dc..3dae655e3b 100644 --- a/src/library/tools/R/build.R +++ b/src/library/tools/R/build.R @@ -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) @@ -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")) ) {