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

Guidelines on how to use custom extract() in distinct package? #210

Open
MatthieuStigler opened this issue Oct 7, 2024 · 2 comments
Open
Labels

Comments

@MatthieuStigler
Copy link
Contributor

Hi

I would like to write a custom extract() function for a custom class and keep that extract.custom in an other package. Do you have guidelines on how to do this (instead of sending PR to texreg), similar to how one would do with a custom tidy function (Create your own broom tidier methods)?

I see for example that package panelvar uses:

extract <- function(model, ...) UseMethod("extract")
extract.pvargmm

and then in NAMESPACE:

export(extract)
S3method(extract,pvarfeols)

It seems this could create some issues, as discussed for tidy?

Please do not define tidy(), glance(), or augment() generics in your package. This will result in namespace conflicts whenever your package is used along other packages that also export tidying methods

Hence the question: do you have advice (or examples) on recommended way to add a custom extract, without sending it to texreg?

Thanks!

@MatthieuStigler MatthieuStigler changed the title Guidelinws on how to use custom extract() in distinct package? Guidelines on how to use custom extract() in distinct package? Oct 7, 2024
@leifeld
Copy link
Owner

leifeld commented Jan 14, 2025

I'm not sure what the official guidance on this is. I've actually been wondering, too. If you (or anyone else) has ideas or comes across any guidance, please post here. My best guess would be something like this:

  1. Import the generic function in your other package:
    importFrom("texreg", "extract")
  2. Implement your method:
    setMethod("extract", "your_class_name", function(model) { ... })
  3. Either put texreg under Imports: in the DESCRIPTION file, or put it under Suggests: and add conditional checks in the code to ensure an error message is printed if texreg is not installed or some other fallback exists. I have some of those in the texreg code as well.
  4. Ideally, add useful documentation and testthat unit tests, but up to you.

@MatthieuStigler
Copy link
Contributor Author

excellent, thanks a lot @leifeld !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants