Skip to content

Need to re-export generic in order to call S3 method defined in a package #4

Description

@jdblischak

The migration guide currently recommends using @exportS3Method lt::lt and then calling lt() directly:

# in R/as_lt.R; registered via @exportS3Method lt::lt

lt/examples/03-gt.Rmd

Lines 362 to 363 in f582454

Users then write `fixed_design_ahr(...) |> summary() |> lt()` in place of
`... |> summary() |> as_gt()`. The full version in **gsDesign2** drives the

This does not work as described. It will fail to find the function lt() since it isn't exported by the package. This would only work if the user independently loads {lt} with library("lt") or qualifies the namespace with lt::lt(), eg fixed_design_ahr(...) |> summary() |> lt::lt().

Given our current problems with as_gt() (keaven/gsDesign#297), I would like to do our best to eliminate these types of search path problems.

The recommendation from r-lib/generics is to re-export the generic:

To use generics with your package, we recommend that you import and re-export the generic(s) of interest.

If we decide to follow this recommendation, we would need to add the following code to the migration guide:

#' @importFrom lt lt
#' @export
lt::lt

I tested this locally with {gsDesign} and {gsDesign2} (using the example code from keaven/gsDesign#297, but replacing as_gt() with lt()). No matter which package is imported first, the call to lt() is properly dispatched to the correct S3 method.

xref: Merck/gsDesign2#629, keaven/gsDesign#282

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions