Skip to content

first() does not work without explicit x argument in a chain inside mutate #3589

Description

@cjyetman

When using first() (or last()) in a chain inside a mutate() (or filter()) command, the x argument has to be explicitly set. This is easy to work around in numerous ways, but the behavior seems strange, so maybe it points to something not quite right.

examples (using R v3.5.0 and dplyr v0.7.5)...

library(dplyr)

mutate(tibble(v1 = 5:6), v2 = 1:4 %>% first())
# Error in mutate_impl(.data, dots) : bad value

clonefirst <- first
mutate(tibble(v1 = 5:6), v2 = 1:4 %>% clonefirst())
# # A tibble: 2 x 2
#      v1    v2
#   <int> <int>
# 1     5     1
# 2     6     1

mutate(tibble(v1 = 5:6), v2 = 1:4 %>% first(.))
# # A tibble: 2 x 2
#      v1    v2
#   <int> <int>
# 1     5     1
# 2     6     1

mutate(tibble(v1 = 5:6), v2 = 1:4 %>% nth(1))
# # A tibble: 2 x 2
#      v1    v2
#   <int> <int>
# 1     5     1
# 2     6     1

mutate(tibble(v1 = 5:6), v2 = 1:4 %>% `[[`(1))
# # A tibble: 2 x 2
#      v1    v2
#   <int> <int>
# 1     5     1
# 2     6     1

mutate(tibble(v1 = 5:6), v2 = first(1:4))
# # A tibble: 2 x 2
#      v1    v2
#   <int> <int>
# 1     5     1
# 2     6     1

1:4 %>% first()
# [1] 1

first(1:4)
# [1] 1

Activity

  1. added a commit that references this issue on May 24, 2018
    8fff3b4
  2. added a commit that references this issue on Sep 11, 2018
  3. lock commented on Nov 20, 2018

    @lock

    This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

  4. locked and limited conversation to collaborators on Nov 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions