0
votes

CRAN policies do not allow that single methods (for generic functions) which are defined in base or recommended packages are replaced. They advice package authors to replace the standard generic and use a xxx.default method which then calls the original standard generic.

An example from my package papeR is as follows:

## overwrite standard generic
plot <- function(x, y, ...)
    UseMethod("plot")

## per default fall back to standard generic
plot.default <- function(x, y, ...)
    graphics::plot(x, y, ...)

## now specify modified plot function for data frames
plot.data.frame <- function(x, variables = names(x), ...)

The complete code can be found on GitHub.

For various generics such as toLatex this method works perfectly. Yet, the above plot method definitions break the standard plot.formula function:

library("devtools")
install_github("hofnerb/papeR")

## still works:
example(plot.formula, package="graphics")    

### But:
library("papeR")
example(plot.formula, package="graphics")
## Error in eval(expr, envir, enclos) : object 'Ozone' not found

I can still use

graphics:::plot.formula(Ozone ~ Wind, data = airquality)    

though. Other plot functions keep working, see e.g.

example("plot", package = "graphics")

Additional Information

In my NAMESPACE I have

importFrom("graphics", "plot", "plot.default", ...)
export(plot, plot.data.frame, ...)
S3method(plot, default)
S3method(plot, data.frame)

For a previous discussion on this topic (with a different focus) see also here.

1

1 Answers

0
votes

For a discussion and solution (define a new_class and use plot.new_class) see https://stat.ethz.ch/pipermail/r-package-devel/2015q3/000463.html