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

filter() forbid matrices #5974

Merged
merged 4 commits into from
Aug 23, 2021
Merged

filter() forbid matrices #5974

merged 4 commits into from
Aug 23, 2021

Conversation

romainfrancois
Copy link
Member

closes #5973

original code from #5972 gives:

library(dplyr, warn.conflicts = FALSE)

tibble(
  y = tibble(
    b = c(1, 2),
    a = c(NA, 1),
  )
) %>% 
  filter(is.na(y))
#> Error: Problem with `filter()` input `..1`.
#> ℹ Input `..1` is `is.na(y)`.
#> x Input `..1` must be a logical vector, not a logical[,2].

Created on 2021-08-06 by the reprex package (v2.0.0)

@romainfrancois
Copy link
Member Author

Relatedly, is it time to be stricter about data frame results in:

} else if(Rf_inherits(res, "data.frame")) {

and just allow logical vectors full stop. Allowing data frame results made sense before we had if_any() and if_all() but not so much now. We could have the error message guide towards if_any() / if_all() for some time.

} else if(Rf_inherits(res, "data.frame")) {
      // disable the warnings entirely for now, so that we can first release
      // if_any() and if_all(), will start warning later
      bool warn = false;

      if (first && warn) {
        SEXP expr = rlang::quo_get_expr(VECTOR_ELT(quos, i));
        bool across = TYPEOF(expr) == LANGSXP && CAR(expr) == dplyr::symbols::across;
        if (across) {
          Rf_warningcall(R_NilValue, "Using `across()` in `filter()` is deprecated, use `if_any()` or `if_all()`");
        } else {
          Rf_warningcall(R_NilValue, "data frame results in `filter()` are deprecated, use `if_any()` or `if_all()`");
        }
      }

      const SEXP* p_res = VECTOR_PTR_RO(res);
      R_xlen_t ncol = XLENGTH(res);
      for (R_xlen_t j = 0; j < ncol; j++) {
        reduce_lgl_and(reduced, p_res[j], n);
      }
    }

    UNPROTECT(2);
  }

@hadley
Copy link
Member

hadley commented Aug 19, 2021

Change looks good and I think your proposed warning makes sense.

@romainfrancois romainfrancois merged commit b206089 into master Aug 23, 2021
@romainfrancois romainfrancois deleted the filter_forbid_matrix_5973 branch August 23, 2021 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

filter() silently accepting matrices
2 participants