r-lib / vctrs

Generic programming with typed R vectors
https://vctrs.r-lib.org
Other
282 stars 65 forks source link

Error when using lubridate arithmetic in if_else loop #1922

Closed chris-nunn closed 3 months ago

chris-nunn commented 3 months ago

Error in mutate(): i In argument: start = if_else(month == "dec", start - years(1), start). Caused by error in vec_ptype_common(): ! Column second (size 432) must match the data frame (size 1). i In file slice.c at line 191. i Install the winch package to get additional debugging info the next time you get this error. i This is an internal error that was detected in the vctrs package. Please report it at https://github.com/r-lib/vctrs/issues with a reprex and the full backtrace.

This is the backtrace:

x

  1. +-... %>% ...
  2. +-dplyr::mutate(...)
  3. +-tidyr::pivot_longer(., future_suitability:historical)
  4. +-dplyr::rename(., future_suitability = value)
  5. +-dplyr::mutate(...)
  6. +-dplyr:::mutate.data.frame(., start = if_else(month == "dec", start - years(1), start))
  7. | -dplyr:::mutate_cols(.data, dplyr_quosures(...), by)
  8. | +-base::withCallingHandlers(...)
  9. | -dplyr:::mutate_col(dots[[i]], data, mask, new_columns)
    1. | -mask$eval_all_mutate(quo)
    2. | -dplyr (local) eval()
    3. +-dplyr::if_else(month == "dec", start - years(1), start)
    4. | -dplyr:::vec_case_when(...)
    5. | -vctrs::vec_ptype_common(!!!everything, .ptype = ptype, .call = call)
    6. -rlang:::stop_internal_c_lib(...)
    7. -rlang::abort(message, call = call, .internal = TRUE, .frame = frame)`
chris-nunn commented 3 months ago

start, the variable being acted on, was not a date