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

Could not find function "lead" with latest version of dplyr #3456

Closed
md0u80c9 opened this issue Mar 23, 2018 · 11 comments
Closed

Could not find function "lead" with latest version of dplyr #3456

md0u80c9 opened this issue Mar 23, 2018 · 11 comments
Assignees
Labels

Comments

@md0u80c9
Copy link

@md0u80c9 md0u80c9 commented Mar 23, 2018

Hi all,

The following line of code works perfectly in the stable version of dplyr. In the development version however (with the newer version of bindrcpp) this generates an error:

Error in mutate_impl(.data, dots) : could not find function "lead"

I'm not aware of lead being affected by the tidy select changes so is the function being parsed differently in some way?

  importedData <- dplyr::mutate(importedData,
    InpatientReadmission = cumsum(
      (dplyr::lead(.data$TeamCode,
                  n = 1,
                  default = -1) > 0) & (.data$TeamCode < 0) * 1))
@krlmlr
Copy link
Member

@krlmlr krlmlr commented Mar 23, 2018

Thanks for the report, this is really important to fix before release. Could you please create a reproducible example that uses a small toy dataset or a commonly available one?

Loading

@md0u80c9
Copy link
Author

@md0u80c9 md0u80c9 commented Mar 24, 2018

Hi,

It looks as though this is as simple as:

test <- tibble::tibble(foo = c(1,2,3))
test <- dplyr::mutate(test, bar = dplyr::lead(.data$test, n = 1, default = -1))

Fails.

test <- tibble::tibble(foo = c(1,2,3))
dplyr::lead(test, n = 1, default = -1)

Works.

Loading

@krlmlr
Copy link
Member

@krlmlr krlmlr commented Mar 24, 2018

Thanks. I can't run your first example, I'm seeing:

test <- tibble::tibble(foo = c(1,2,3))
test <- dplyr::mutate(test, bar = dplyr::lead(.data$test, n = 1, default = -1))
#> Error in mutate_impl(.data, dots): Evaluation error: Column `test` not found in `.data`.

Created on 2018-03-24 by the reprex package (v0.2.0).

Also, for the second example I'm seeing:

test <- tibble::tibble(foo = c(1,2,3))
dplyr::lead(test, n = 1, default = -1)
#> # A tibble: 3 x 1
#>     foo
#> * <dbl>
#> 1   -1.
#> 2   NA 
#> 3   NA

Created on 2018-03-24 by the reprex package (v0.2.0).

What do you expect lead() on a data frame to return?

Loading

@md0u80c9
Copy link
Author

@md0u80c9 md0u80c9 commented Mar 24, 2018

Apologies - that first example should be:

test <- tibble::tibble(foo = c(1,2,3))
test <- dplyr::mutate(test, bar = dplyr::lead(.data$foo, n = 1, default = -1))

On dplyr 0.7.4 you get:

> test
# A tibble: 3 x 2
    foo   bar
  <dbl> <dbl>
1    1.    2.
2    2.    3.
3    3.   -1.

Output from dplyr 0.7.4.9002:

> test <- tibble::tibble(foo = c(1,2,3))
> test <- dplyr::mutate(test, bar = dplyr::lead(.data$foo, n = 1, default = -1))
Error in mutate_impl(.data, dots) : could not find function "lead"

Loading

@krlmlr
Copy link
Member

@krlmlr krlmlr commented Mar 24, 2018

Thanks, confirmed:

@romainfrancois: Could you please take a look?

Loading

@krlmlr krlmlr added bug and removed reprex labels Mar 24, 2018
@romainfrancois romainfrancois self-assigned this Mar 24, 2018
romainfrancois added a commit that referenced this issue Mar 24, 2018
…oses #3456

I had to copy and slightly change findFun, because the one from the R api would potentially lead to C++ destructors not being called.
@md0u80c9
Copy link
Author

@md0u80c9 md0u80c9 commented Mar 27, 2018

Just followed the thread (#3456). Don't think the current fixes address the above? Certainly I can still produce the original error that led me to the report with the latest version of dplyr (pulled from GitHub just now). Just tested with the reprex and I still see the same too.

Loading

@romainfrancois
Copy link
Member

@romainfrancois romainfrancois commented Mar 27, 2018

@md0u80c9 did you try with the fix-issue-3456 branch?

install_github( "tidyverse/dplyr", ref = "fix-issue-3456" )

Loading

@md0u80c9
Copy link
Author

@md0u80c9 md0u80c9 commented Mar 27, 2018

Tested with that branch now - and that seems to work both on the reprex and on my original code. Great stuff :-).

Loading

@md0u80c9 md0u80c9 closed this Mar 27, 2018
@romainfrancois
Copy link
Member

@romainfrancois romainfrancois commented Mar 27, 2018

Thanks for taking the time to try it.

Just for the record, a commit message in the branch would have closed the issue automatically on merge.

Not a big deal because we usually merge fast, but potentially a problem on others repos.

Thanks again for reporting the problem in the first place.

Loading

@krlmlr
Copy link
Member

@krlmlr krlmlr commented Mar 29, 2018

Reopening, will close when PR is merged.

Loading

@krlmlr krlmlr reopened this Mar 29, 2018
@krlmlr krlmlr closed this in #3458 Apr 10, 2018
krlmlr added a commit that referenced this issue Apr 10, 2018
- The hybrid evaluator finds functions from dplyr even if dplyr is not attached (#3456).
@lock
Copy link

@lock lock bot commented Oct 7, 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/

Loading

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

Successfully merging a pull request may close this issue.

3 participants