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

Why map2() does not work with seq.int() but works with seq()? #839

Closed
irudnyts opened this issue Sep 23, 2021 · 4 comments
Closed

Why map2() does not work with seq.int() but works with seq()? #839

irudnyts opened this issue Sep 23, 2021 · 4 comments
Labels
bug an unexpected problem or unintended behavior map 🗺️

Comments

@irudnyts
Copy link

I tried to use the seq.int() method instead of the seq() generics in map2(), but I receive strange errors.

The code with the generics:

library(reprex)
library(purrr)

x <- 1:3
y <- 4:6

map2(x, y, seq)
#> [[1]]
#> [1] 1 2 3 4
#> 
#> [[2]]
#> [1] 2 3 4 5
#> 
#> [[3]]
#> [1] 3 4 5 6

But when I use seq.int(), I get this (even if I specify by, and/or length.out, and/or along.with):

library(reprex)
library(purrr)

x <- 1:3
y <- 4:6

map2(x, y, seq.int)
#> Error in .f(.x[[i]], .y[[i]], ...): argument "by" is missing, with no default

At the same time, both chunks below (using mapply() and defining nesting function) work:

library(reprex)
library(purrr)

x <- 1:3
y <- 4:6

mapply(seq.int, from = x, to = y, SIMPLIFY = FALSE)
#> [[1]]
#> [1] 1 2 3 4
#> 
#> [[2]]
#> [1] 2 3 4 5
#> 
#> [[3]]
#> [1] 3 4 5 6
library(reprex)
library(purrr)

x <- 1:3
y <- 4:6

my_seq <- function(from, to) {
    seq.int(from, to)
}

map2(x, y, my_seq)
#> [[1]]
#> [1] 1 2 3 4
#> 
#> [[2]]
#> [1] 2 3 4 5
#> 
#> [[3]]
#> [1] 3 4 5 6
@irudnyts
Copy link
Author

Not sure though if I'd better ask this on Stackoverflow 🙂

@lionel-
Copy link
Member

lionel- commented Sep 23, 2021

This is an rlang issue:

rlang::as_closure(seq.int)(1, 2)
#> Error: argument "by" is missing, with no default

@stanstrup
Copy link

Dunno...
but map2(x, y, ~ seq.int(..1, ..2)) works.

@hadley hadley added bug an unexpected problem or unintended behavior map 🗺️ labels Aug 23, 2022
@hadley
Copy link
Member

hadley commented Aug 27, 2022

I suspect there's nothing we can do here; seq.int() is a primitive function and presumably has special handing of missing values that we can't easily replicate. But I've filed an issue at r-lib/rlang#1468 to remind us to look into it more.

@hadley hadley closed this as completed Aug 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior map 🗺️
Projects
None yet
Development

No branches or pull requests

4 participants