Skip to content

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

@ambevill

Description

@ambevill

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

Metadata

Metadata

Assignees

No one assigned

    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