RConsortium / S7

S7: a new OO system for R
https://rconsortium.github.io/S7
Other
399 stars 33 forks source link

length method vs R CMD Check #342

Closed jonthegeek closed 1 year ago

jonthegeek commented 1 year ago

I'm not sure how to reprex this, because so far I only see the issue inside R CMD Check. This is the warning I get:

❯ checking for code/documentation mismatches ... WARNING Warning in formals(fun) : argument is not a function

I got it by trying to define a length method.

S7::method(length, rapid) <- function(x) length(x@info)

It otherwise works with the dev version of S7 (but fails with the CRAN version).

I'm assuming that it's somehow related to length being a primitive rather than an actual S3 generic, but beyond that I'm not sure where to look.

hadley commented 1 year ago

Would you mind providing a basic package reprex?

jonthegeek commented 1 year ago

Sure, I'll put something together, including the failed check.

jonthegeek commented 1 year ago

https://github.com/jonthegeek/S7primitivereprex/actions/runs/6149344761/job/16685015875?pr=1

Somewhat shockingly, I had to include the R/S7primitivereprex-package.R file (or possibly specifically the corresponding Rd) to get the error, specifically this piece:

#' @keywords internal
"_PACKAGE"

I hope that helps track it down!

hadley commented 1 year ago

You just need one documentation file to be present, which I guess isn't too surprising given that the error comes from the "checking for code/documentation mismatches" check.

hadley commented 1 year ago

I see the same problem when registering a method for mean(), so it doesn't appear to be just related to primitives.

You can see the problem more easily with tools::codoc("S7primitivereprex", ".")

A bit of rlang gymnastics yields a back trace for the warning:

    ▆
  1. ├─base::withCallingHandlers(...)
  2. ├─tools::codoc("S7primitivereprex", ".")
  3. │ └─base::lapply(functions_in_S3Table, function(f) formals(S3Table[[f]]))
  4. │   └─tools (local) FUN(X[[i]], ...)
  5. │     └─base::formals(S3Table[[f]])

And it's calling it with S3Table[[".S7_methods"]] which is added by external_methods_add().

hadley commented 1 year ago

@jonthegeek thanks for trying S7 out and reporting these problems!

jonthegeek commented 1 year ago

Happy to help! I'd been trying to decide how to structure a data--of-a-particular-shape-focused package, and S7 appeared on CRAN just in time 😊