From Thom@@@SOEIRO @end|ng |rom @p-hm@|r  Wed Dec  1 23:41:04 2021
From: Thom@@@SOEIRO @end|ng |rom @p-hm@|r (SOEIRO Thomas)
Date: Wed, 1 Dec 2021 22:41:04 +0000
Subject: [Rd] Add ... to Reduce?
Message-ID: <1638398464828.91211@ap-hm.fr>

Dear list,

Currently, it is needed to use anonymous functions to pass additional parameters to f in Reduce.

The following patch adds ... to pass additional arguments directly and seems to work in simple cases (see example below).

However, since this was not available (even though it is common for similar functions), I suspect that I am missing something...

Best,

Thomas


dfs <- list(x = warpbreaks)
dfs$x$id <- seq_along(dfs$x$breaks)
dfs$y <- dfs$x[1:15, ]
dfs$z <- dfs$x[20:35, ]

identical(
  Reduce(function(...) merge(..., by = "id", all = TRUE), dfs),
  Reduce(merge, dfs, by = "id", all = TRUE)
)


diff -u orig/funprog.R mod/funprog.R
--- orig/funprog.R	2021-12-01 23:02:09.710231318 +0100
+++ mod/funprog.R	2021-12-01 23:23:58.591120101 +0100
@@ -1,7 +1,7 @@
 #  File src/library/base/R/funprog.R
 #  Part of the R package, https://www.R-project.org
 #
-#  Copyright (C) 1995-2014 The R Core Team
+#  Copyright (C) 1995-2021 The R Core Team
 #
 #  This program is free software; you can redistribute it and/or modify
 #  it under the terms of the GNU General Public License as published by
@@ -17,7 +17,7 @@
 #  https://www.R-project.org/Licenses/
 
 Reduce <-
-function(f, x, init, right = FALSE, accumulate = FALSE)
+function(f, x, init, right = FALSE, accumulate = FALSE, ...)
 {
     mis <- missing(init)
     len <- length(x)
@@ -49,11 +49,11 @@
     if(!accumulate) {
         if(right) {
             for(i in rev(ind))
-                init <- forceAndCall(2, f, x[[i]], init)
+                init <- forceAndCall(2, f, x[[i]], init, ...)
         }
         else {
             for(i in ind)
-                init <- forceAndCall(2, f, init, x[[i]])
+                init <- forceAndCall(2, f, init, x[[i]], ...)
         }
         init
     }
@@ -66,13 +66,13 @@
             if(right) {
                 out[[len]] <- init
                 for(i in rev(ind)) {
-                    init <- forceAndCall(2, f, x[[i]], init)
+                    init <- forceAndCall(2, f, x[[i]], init, ...)
                     out[[i]] <- init
                 }
             } else {
                 out[[1L]] <- init
                 for(i in ind) {
-                    init <- forceAndCall(2, f, init, x[[i]])
+                    init <- forceAndCall(2, f, init, x[[i]], ...)
                     out[[i]] <- init
                 }
             }
@@ -80,14 +80,14 @@
             if(right) {
                 out[[len]] <- init
                 for(i in rev(ind)) {
-                    init <- forceAndCall(2, f, x[[i]], init)
+                    init <- forceAndCall(2, f, x[[i]], init, ...)
                     out[[i]] <- init
                 }
             }
             else {
                 for(i in ind) {
                     out[[i]] <- init
-                    init <- forceAndCall(2, f, init, x[[i]])
+                    init <- forceAndCall(2, f, init, x[[i]], ...)
                 }
                 out[[len]] <- init
             }
diff -u orig/funprog.Rd mod/funprog.Rd
--- orig/funprog.Rd	2021-12-01 23:02:38.400738386 +0100
+++ mod/funprog.Rd	2021-12-01 23:29:28.993976101 +0100
@@ -21,7 +21,7 @@
   given function.
 }
 \usage{
-Reduce(f, x, init, right = FALSE, accumulate = FALSE)
+Reduce(f, x, init, right = FALSE, accumulate = FALSE, ...)
 Filter(f, x)
 Find(f, x, right = FALSE, nomatch = NULL)
 Map(f, ...)
@@ -44,7 +44,7 @@
     combination is used.}
   \item{nomatch}{the value to be returned in the case when
     \dQuote{no match} (no element satisfying the predicate) is found.}
-  \item{\dots}{vectors.}
+  \item{\dots}{arguments to be passed to FUN.}
 }
 \details{
   If \code{init} is given, \code{Reduce} logically adds it to the start





[Rd] Add ... to Reduce?
SOEIRO Thomas