[R-pkg-devel] Problems with :::

Duncan Murdoch murdoch.duncan at gmail.com
Thu Jan 28 14:20:48 CET 2016


On 28/01/2016 7:47 AM, David Scott wrote:
> I am trying to incorporate a print method for flat tables into the
> package xtable which I maintain.
>
> To format the flat table before printing, I wish to use format.ftable
> from the base package stats.
> This is unfortunately not exported, so R CMD check --as-cran produces a
> warning because I access that function using stats:::format.ftable.
>
> So, having read the thread about this problem, I think I should copy the
> function into my package. I do that, and declare format.ftable as an S3
> format method. Now I get a different warning:
>
> Registered S3 method from a standard package overwritten by 'xtable':
>    method        from
>    format.ftable stats
>
> I am at a loss. Any suggestions?

stats::format() is exported, and it will delegate to format.ftable if 
the class of the object is "ftable".  So the normal solution is just to 
call stats::format() on your object.

If your object has a different class (e.g. "mytable"), it might be that 
you need to do this from your own format.mytable method.  Then 
NextMethod() is supposed to work, assuming the class is really 
c("mytable", "ftable").

If the class is just "mytable", then you'll have to change it to 
"ftable" before calling stats::format().

Duncan Murdoch



More information about the R-package-devel mailing list