harrelfe / Hmisc

Harrell Miscellaneous
Other
205 stars 81 forks source link

restore all the classes on [.describe #130

Open romainfrancois opened 4 years ago

romainfrancois commented 4 years ago

I believe this caused the package neuropsychology to fail against dplyr 1.0.0 because a data frame with additional class describe is [ and this method only keeps "describe" as the class.

related to https://github.com/tidyverse/dplyr/issues/5240

romainfrancois commented 4 years ago

For reference, here is how neuropsychology fails:

[master*] 71.2 MiB ❯ revdepcheck::revdep_details(, "neuropsychology")
══ Reverse dependency check ═══════════════════════════ neuropsychology 0.5.0 ══

Status: BROKEN

── Still failing

✖ checking dependencies in R code ... NOTE

── Newly failing

✖ checking examples ... ERROR

── Before ──────────────────────────────────────────────────────────────────────
❯ checking dependencies in R code ... NOTE
  Namespaces in Imports field not imported from:
    ‘htmlTable’ ‘lme4’ ‘stringi’
    All declared Imports should be used.

0 errors ✔ | 0 warnings ✔ | 1 note ✖

── After ───────────────────────────────────────────────────────────────────────
❯ checking examples ... ERROR
  Running examples in ‘neuropsychology-Ex.R’ failed
  The error most likely occurred in:

  > ### Name: describe
  > ### Title: Description of dataframes.
  > ### Aliases: describe
  >
  > ### ** Examples
  >
  > require(neuropsychology)
  >
  > df <- personality
  >
  > describe(df)
  Warning: `transmute_()` is deprecated as of dplyr 0.7.0.
  Please use `transmute()` instead.
  See vignette('programming') for more help
  This warning is displayed once every 8 hours.
  Call `lifecycle::last_warnings()` to see where this warning was generated.
  Error in round(df[2:10], 2) :
    non-numeric argument to mathematical function
  Calls: describe
  Execution halted

❯ checking dependencies in R code ... NOTE
  Namespaces in Imports field not imported from:
    ‘htmlTable’ ‘lme4’ ‘stringi’
    All declared Imports should be used.

1 error ✖ | 0 warnings ✔ | 1 note ✖

in relation with the describe function : https://github.com/romainfrancois/neuropsychology.R/blob/master/R/describe.R#L10 that ends up calling dplyr::mutate() which uses [.describe https://github.com/tidyverse/dplyr/blob/master/R/mutate.R#L202

romainfrancois commented 4 years ago

Unfortunately I haven't been able to test this thoroughly as I was not able to build Hmisc locally.

romainfrancois commented 4 years ago

We've now merged extra checking in dplyr so that the error becomes:

library(dplyr, warn.conflicts = FALSE)

neuropsychology::personality %>% 
  select(where(is.numeric)) %>% 
  psych::describe() %>% 
  transmute(a = 1)
#> Error: Can't reconstruct data frame.
#> x The `[` method for class <psych/describe/data.frame> must return a data frame.
#> ℹ It returned a <describe>.

Created on 2020-05-20 by the reprex package (v0.3.0)

harrelfe commented 3 years ago

Thanks working on this. I would need a formal pull request and testing before I can proceed. Sorry I don't have time soon to work on this myself.