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

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

Closed
cjyetman opened this issue May 22, 2018 · 1 comment
Closed
Assignees

Comments

@cjyetman
Copy link
Contributor

@cjyetman cjyetman commented May 22, 2018

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
@lock
Copy link

@lock lock bot commented Nov 20, 2018

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/

@lock lock bot locked and limited conversation to collaborators Nov 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants