Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Foreach .combine ignores initial value #143

Closed
mschubert opened this issue May 3, 2019 · 0 comments
Closed

Foreach .combine ignores initial value #143

mschubert opened this issue May 3, 2019 · 0 comments
Labels

Comments

@mschubert
Copy link
Owner

Consider the default .combine function and intial value for foreach

red = function (a, ...) c(a, list(...))
init = substitute(list())

This currently gives the wrong result

Reduce(red, list(matrix(c(1,2),ncol=1),matrix(c(2,3),ncol=1)))
# will separate the first matrix into its elements

Fixing needs an additional eval() on the intial value

Reduce(red, list(matrix(c(1,2),ncol=1),matrix(c(2,3),ncol=1)), init=init)
# additonal list() element in beginning
Reduce(red, list(matrix(c(1,2),ncol=1),matrix(c(2,3),ncol=1)), init=eval(init))
# all good
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant