[R-pkg-devel] Define S4 method for generic in other package

Duncan Murdoch murdoch.duncan at gmail.com
Fri Aug 28 13:25:38 CEST 2015


On 28/08/2015 4:23 AM, Thierry Onkelinx wrote:
> Dear all,
> 
> I'm trying to define a new S4 method for a generics defined in an
> other package. Here is my attempt, but that isn't working.
> 
> bar <- function(a, b) is defined as generic and S4 method in the package foo
> 
> #' @importFrom foo bar
> #' @importMethodsFrom foo bar

I'd advise against using Roxygen2 declarations.  They might be right,
they might not, but you limit the number of people who can answer your
question to those who know *both* Roxygen2 *and* S4 details.

The Writing R Extensions manual describes the NAMESPACE requirements to
do what you want pretty clearly, but I have no idea if the declarations
above satisfy them.

Duncan Murdoch

> setMethod(
>   f = "bar",
>   signature = signature(A = "myClass"),
>   definition = function(
>     a,
>     b
>   ){
>     bar(
>       a = myClass at A,
>       b = myClass at B
>     )
>   }
> )
> 
> When I build my package I get the error "no existing definition for
> function 'bar'".
> 
> Any suggestions?
> 
> Best regards,
> 
> ir. Thierry Onkelinx
> Instituut voor natuur- en bosonderzoek / Research Institute for Nature
> and Forest
> team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
> Kliniekstraat 25
> 1070 Anderlecht
> Belgium
> 
> To call in the statistician after the experiment is done may be no
> more than asking him to perform a post-mortem examination: he may be
> able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
> The plural of anecdote is not data. ~ Roger Brinner
> The combination of some data and an aching desire for an answer does
> not ensure that a reasonable answer can be extracted from a given body
> of data. ~ John Tukey
> 
> ______________________________________________
> R-package-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>



More information about the R-package-devel mailing list