[R-pkg-devel] Private S3 Method not Found

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Mon Feb 17 16:14:24 CET 2020


On 17/02/2020 10:05 a.m., bill using denney.ws wrote:
> Hello,
> 
>   
> 
> I'm working on a function in a package that will provide an exported
> function that will convert formula to LaTeX equations.  For that, it
> recursively goes through the formula converting objects of class "formula",
> "call", "name", and "(" to LaTeX.
> 
>   
> 
> I have a private S3 generic function that I'm using for the conversion, but
> for some reason, the generic is not detected, and checking the package fails
> for that reason
> (https://travis-ci.org/billdenney/bsd.report/jobs/651510333):
> 
>   
> 
> no applicable method for 'knit_print_helper_formula' applied to an object of
> class "name"
> 
> Backtrace:
> 
>    1. testthat::expect_equal(...)
> 
>    4. bsd.report:::knit_print.formula(a ~ b(c))
> 
>    6. bsd.report:::knit_print_helper_formula.formula(x, ..., replacements =
> replacements)
> 
>    9. bsd.report:::knit_print_helper_formula.call(x[[3]], ...)
> 
> 10. bsd.report:::knit_print_helper_formula.function_call(x, ...)
> 
> 11. base::sapply(...)
> 
> 12. base::lapply(X = X, FUN = FUN, ...)
> 
> 13. bsd.report:::FUN(X[[i]], ...)
> 
>   
> 
> But, there is a knit_print_helper_formula.name function call defined
> (https://github.com/billdenney/bsd.report/blob/master/R/knit_print.formula.R
> #L60-L79):
> 
>   
> 
> knit_print_helper_formula <- function(x, ...) {
> 
>    UseMethod("knit_print_helper_formula")
> 
> }
> 
>   
> 
> # Some other methods
> 
>   
> 
> knit_print_helper_formula.name <- function(x, ...) {
> 
> # Function body
> 
> }
> 
>   
> 
> Does anyone know why the S3 method for name class objects is not found when
> checking the package?
> 

I think you need to register knit_print_helper_formula.name as an S3 
method even if the generic is not exported.  I forget whether you do 
this in the NAMESPACE file or at runtime using registerS3method.

Duncan Murdoch



More information about the R-package-devel mailing list