RConsortium / S7

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

Methods need to be in the same .R file as their class definition in packages? #358

Closed jeffkimbrel closed 12 months ago

jeffkimbrel commented 12 months ago

I have an S7 class that I created with S7::new_class() in one .R file, and then each associated method I grouped with it's generic into their own .R files.

When running check() or document() the S7::method call can't find my class and I get an error. But, moving all generics/methods that use one of my newly defined classes into the same .R file allows all checks and documentation to work.

So, is this the expected behavior and all related class methods/generics should be together?

Or, is it unexpected and generics/methods elsewhere should be able to find their objects? I was tempted to run use_package and add my actual package, but that seemed weird to have to declare that my package uses itself.

Thanks for any help.

hadley commented 12 months ago

Basically a duplicate of #325 — class objects are objects, so they need to be defined before they're used.