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

avoid matrices in filter() #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

romainfrancois
Copy link

We're about to release dplyr 1.0.8 and this package currently fail against it, because one example uses matrices in filter() and we are trying to be stricter about what is allowed.

We currently see:

── After ─────────────────────────────────────────────────────────────────────────────────────────────────────
> checking examples ... ERROR
  Running examples in ‘ggcharts-Ex.R’ failed
  The error most likely occurred in:
  
  > ### Name: diverging_bar_chart
  > ### Title: Diverging Bar Chart
  > ### Aliases: diverging_bar_chart
  > 
  > ### ** Examples
  > 
  > if (requireNamespace("tidyr")) {
  +   library(magrittr)
  +   data(biomedicalrevenue)
  +   biomedicalrevenue %>%
  +   dplyr::filter(year > 2016) %>%
  +   tidyr::pivot_wider(
  +     values_from = revenue,
  +     names_from = year,
  +     names_prefix = "revenue_"
  +   ) %>%
  +   dplyr::mutate(diff = revenue_2018 - revenue_2017) %>%
  +   diverging_bar_chart(company, diff)
  + }
  Loading required namespace: tidyr
  > 
  > data(mtcars)
  > mtcars_z <- dplyr::transmute(
  +   .data = mtcars,
  +   model = row.names(mtcars),
  +   hpz = scale(hp)
  + )
  > 
  > diverging_bar_chart(mtcars_z, model, hpz)
  Error: Problem while computing `..1 = hpz >= 0`.
  ✖ Input `..1` must be a logical vector, not a logical[,1].
  Backtrace:
       ▆
    1. ├─ggcharts::diverging_bar_chart(mtcars_z, model, hpz)
    2. │ └─ggcharts:::diverging_chart(...)
    3. │   ├─ggplot2::geom_text(...)
    4. │   │ └─ggplot2::layer(...)
    5. │   │   └─ggplot2::fortify(data)
    6. │   ├─dplyr::filter(data, !!y >= 0)
    7. │   └─dplyr:::filter.data.frame(data, !!y >= 0)
    8. │     └─dplyr:::filter_rows(.data, ..., caller_env = caller_env())
    9. │       └─dplyr:::filter_eval(dots, mask = mask, error_call = error_call)
   10. │         ├─base::withCallingHandlers(...)
   11. │         └─mask$eval_all_filter(dots, env_filter)
   12. ├─dplyr:::dplyr_internal_error(...)
   13. │ └─rlang::abort(class = c(class, "dplyr:::internal_error"), dplyr_error_data = data)
   14. │   └─rlang:::signal_abort(cnd, .file)
   15. │     └─base::signalCondition(cnd)
   16. └─dplyr `<fn>`(`<dpl:::__>`)
  Execution halted

1 error x | 0 warnings ✓ | 0 notes ✓

I have submitted a pull request to dplyr so that you'd get a warning for a matrix with 1 column, instead of an error: tidyverse/dplyr#6083 but I still believe using matrices (even with just one columns) should be avoided altogether, which is what this pull request does.

Copy link
Owner

@thomas-neitmann thomas-neitmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much @romainfrancois!

@codecov-commenter
Copy link

Codecov Report

Merging #100 (3cb8348) into master (fa263d1) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff           @@
##           master    #100   +/-   ##
======================================
  Coverage    4.78%   4.78%           
======================================
  Files          14      14           
  Lines         627     627           
======================================
  Hits           30      30           
  Misses        597     597           
Impacted Files Coverage Δ
R/diverging_chart.R 0.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fa263d1...3cb8348. Read the comment docs.

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.

None yet

3 participants