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

materialize_binding error when using rowwise on zero-row data.frame #4224

Closed
ambevill opened this issue Feb 25, 2019 · 2 comments
Closed

materialize_binding error when using rowwise on zero-row data.frame #4224

ambevill opened this issue Feb 25, 2019 · 2 comments

Comments

@ambevill
Copy link

@ambevill ambevill commented Feb 25, 2019

Since upgrading to 0.8.0.1, I've noticed unexpected behavior for rowwise operations if the arg has zero rows. This is an edge case, but I don't think it makes sense to require guards to check for zero-row data.frames.


Brief description of the problem

library(dplyr)
packageVersion('dplyr')

# any function
pass_through = function(x) { x }

# as expected, this passes an empty character array into pass_through
data.frame(a = character()) %>%
  mutate(b = pass_through(a))

# this unexpectedly crashes; output below
data.frame(a = character()) %>%
  rowwise() %>%
  mutate(b = pass_through(a))

Crash traceback:

Error: Evaluation error: subscript out of bounds. 
15.
stop(structure(list(message = "Evaluation error: subscript out of bounds.", 
    call = NULL, cppstack = NULL), class = c("Rcpp::eval_error", 
"C++Error", "error", "condition"))) 
14.
materialize_binding(index, mask_proxy_xp) 
13.
(function () 
{
    materialize_binding(index, mask_proxy_xp)
})() 
12.
pass_through(a) 
11.
mutate_impl(.data, dots, caller_env()) 
10.
mutate.tbl_df(., b = pass_through(a)) 
9.
mutate(., b = pass_through(a)) 
8.
function_list[[k]](value) 
7.
withVisible(function_list[[k]](value)) 
6.
freduce(value, `_function_list`) 
5.
`_fseq`(`_lhs`) 
4.
eval(quote(`_fseq`(`_lhs`)), env, env) 
3.
eval(quote(`_fseq`(`_lhs`)), env, env) 
2.
withVisible(eval(quote(`_fseq`(`_lhs`)), env, env)) 
1.
data.frame(a = character()) %>% rowwise() %>% mutate(b = pass_through(a))

Windows 10, installed via CRAN binary, R 3.5.1

@batpigandme
Copy link
Member

@batpigandme batpigandme commented Feb 25, 2019

Adding reprex with output:

library(dplyr)

# any function
pass_through = function(x) { x }

# as expected, this passes an empty character array into pass_through
data.frame(a = character()) %>%
  mutate(b = pass_through(a))
#> [1] a b
#> <0 rows> (or 0-length row.names)

# this unexpectedly crashes; output below
data.frame(a = character()) %>%
  rowwise() %>%
  mutate(b = pass_through(a))
#> Error: Evaluation error: subscript out of bounds.

Created on 2019-02-25 by the reprex package (v0.2.1)

@lock
Copy link

@lock lock bot commented Aug 31, 2019

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 Aug 31, 2019
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.

None yet
2 participants