Skip to content

Commit 1e4715b

Browse files
BUG FIX: value(..., reduce = structure("+", init = 42)) did not work
1 parent d59d0ee commit 1e4715b

File tree

5 files changed

+27
-21
lines changed

5 files changed

+27
-21
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: future
2-
Version: 1.67.0-9013
2+
Version: 1.67.0-9015
33
Title: Unified Parallel and Distributed Processing in R for Everyone
44
Depends:
55
R (>= 3.2.0)

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ repeat. This release fixes a few more regressions introduced in
2626
until the machine ran out of resources. This bug was introduced in
2727
**future** (>= 1.67.0) [2025-07-29].
2828

29+
* `value(..., reduce = structure(`+`, init = 42))` is not supported,
30+
because `+` is a primitive function and one must not set attributes
31+
on primitive functions. `value()` detects this and produces an
32+
error suggestion to use `reduce = structure("+", init = 42)`
33+
instead. The latter still gave the same error, which is now fixed.
34+
2935

3036
# Version 1.67.0 [2025-07-29]
3137

R/core_api-value.R

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -470,27 +470,27 @@ value.list <- function(x, idxs = NULL, recursive = 0, reduce = NULL, stdout = TR
470470
reduce <- fcn
471471
} else if (is.function(reduce)) {
472472
stop_if_not(is.function(reduce))
473-
if (!is.primitive(reduce)) {
473+
if (is.primitive(reduce)) {
474+
## SPECIAL CASE: Protect against mistakes
475+
## See R-devel thread '[Rd] structure(<primitive function>, ...) is
476+
## sticky: a bug, or should it be an error?' on 2025-03-19
477+
## <https://stat.ethz.ch/pipermail/r-devel/2025-March/083892.html>
478+
if (is.primitive(reduce) && !is.null(attr(reduce, "init", exact = TRUE))) {
479+
## FIXME?: At least in R 4.4.3, none of the primitive functions have
480+
## attributes. Because of that, we could do attributes(reduce) <- NULL
481+
## here before throwing the error. But is that a safe assumption?
482+
name <- name_of_function(reduce)
483+
nameq <- name
484+
if (!grepl("^[[:alpha:]]", nameq)) nameq <- sprintf("`%s`", nameq)
485+
stop(sprintf("You must not set an 'init' reduce value on 'base' function %s(), because it is a primitive function. You can use 'reduce = structure(\"%s\", init = <value>)' instead", nameq, name))
486+
}
487+
} else {
474488
args <- names(formals(reduce))
475489
if (length(args) == 0) {
476490
stop("The 'reduce' function must take at least one argument")
477491
}
478492
}
479-
}
480-
481-
## SPECIAL CASE: Protect against mistakes
482-
## See R-devel thread '[Rd] structure(<primitive function>, ...) is
483-
## sticky: a bug, or should it be an error?' on 2025-03-19
484-
## <https://stat.ethz.ch/pipermail/r-devel/2025-March/083892.html>
485-
if (is.primitive(reduce) && !is.null(attr(reduce, "init", exact = TRUE))) {
486-
## FIXME?: At least in R 4.4.3, none of the primitive functions have
487-
## attributes. Because of that, we could do attributes(reduce) <- NULL
488-
## here before throwing the error. But is that a safe assumption?
489-
name <- name_of_function(reduce)
490-
nameq <- name
491-
if (!grepl("^[[:alpha:]]", nameq)) nameq <- sprintf("`%s`", nameq)
492-
stop(sprintf("You must not set an 'init' reduce value on 'base' function %s(), because it is a primitive function. You can use 'reduce = structure(\"%s\", init = <value>)' instead", nameq, name))
493-
}
493+
}
494494
} ## if (do_reduce)
495495

496496
stop_if_not(

incl/value.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ vs <- unlist(vs)
2525
message("The ten averages are: ", paste(vs, collapse = ", "))
2626

2727
## The values as a vector (by reducing)
28-
vs <- value(fs, reduce = `c`)
28+
vs <- value(fs, reduce = c)
2929
message("The ten averages are: ", paste(vs, collapse = ", "))
3030

3131
## Calculate the sum of the averages (by reducing)
32-
total <- value(fs, reduce = `sum`)
32+
total <- value(fs, reduce = `+`)
3333
message("The sum of the ten averages is: ", total)

man/value.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)