[R-pkg-devel] Generic method redefinition and dispatch

Pedro J. Aphalo pedro.aphalo at helsinki.fi
Thu Aug 10 13:41:08 CEST 2017


Hello,

Package 'ggplot2' defines `ggplot()` as an S3 generic.

My package 'ggspectra' defines some specializations of ggplot() for 
additional classes, which work as expected together with all packages 
extending 'ggplot2' that I have tested, except for 'ggtern'.

Package 'ggtern' imports 'ggplot2' and then redefines the ggplot() 
generic with exactly the same code as in 'ggplot2' itself.

If one attempts to use my package and 'ggtern' in the same session, 
dispatch fails for the ggplot() specializations defined in my package, 
unless an explicit call to ggplot2::ggpplot() is used.

I do not understand why the generic needs to be redefined in 'ggtern', 
and although I have raised an issue for 'ggtern' last November, the just 
released version of 'ggtern' retains the redefinition of the generic.

So, I have some questions:

1) Can I do anything in my own package to ensure that method dispatch 
works correctly even after 'ggtern' is attached?

2) Is it good practice for a package to redefine a generic from an 
imported package?

3) Is it possible to redefine a generic, without disturbing the dispatch 
of specializations already known to R?

Thanks in advance for any insights,

Pedro.

-- 
------------------------------------------------------------------------
Pedro J. Aphalo
University Lecturer, Principal Investigator
(Office 4417, Biocenter 3, Viikinkaari 1)

Department of Biosciences
Plant Biology
P.O. Box 65
00014 University of Helsinki
Finland

e-mail: pedro.aphalo at helsinki.fi <mailto:pedro.aphalo at helsinki.fi>
Tel. (mobile) +358 50 4150623
Tel. (office) +358 2941 57897

------------------------------------------------------------------------
*Web sites and blogs*
Web site (research group): http://blogs.helsinki.fi/senpep-blog/
Web site (own teaching): http://www.helsinki.fi/people/pedro.aphalo/
Web site (using R in photobiology): http://www.r4photobiology.info/
------------------------------------------------------------------------
*Societies*
UV4Plants <http://www.uv4plants.org/> (communications officer), ESP 
<http://www.photobiology.eu/> (member) SEB <http://www.sebiology.org/> 
(member), BES <http://www.britishecologicalsociety.org/> (member), SPPS 
<http://www.spps.fi/> (member), SMS 
<http://www.metsatieteellinenseura.fi/english> (member), TUG 
<http://tug.org/> (member), FOAS <http://www.foastat.org/> (member).
------------------------------------------------------------------------

	[[alternative HTML version deleted]]



More information about the R-package-devel mailing list