[R-pkg-devel] Problems with :::
Berry Boessenkool
berryboessenkool at hotmail.com
Mon Feb 1 10:39:59 CET 2016
> if (!inherits(x, "ftable"))
> if(class(x) == "ftable") ## really really bad
Thank you Martin, for pointing that out!
I was not aware of it yet and changed all occurences in my package and added in note in my R course material.
(This message is mainly an encouragement that some people actually read the mails and act on it, even if not usually replying).
Regards,
Berry
> From: maechler at stat.math.ethz.ch
> Date: Mon, 1 Feb 2016 09:49:26 +0100
> To: kirill.mueller at ivt.baug.ethz.ch
> CC: r-package-devel at r-project.org
> Subject: Re: [R-pkg-devel] Problems with :::
>
> >>>>> Kirill Müller <kirill.mueller at ivt.baug.ethz.ch>
> >>>>> on Thu, 28 Jan 2016 17:42:12 +0100 writes:
>
> > On 28.01.2016 14:20, Duncan Murdoch wrote:
> >> If the class is just "mytable", then you'll have to
> >> change it to "ftable" before calling stats::format().
> > Side note: The following will fail, because format.ftable
> > double-checks the class of its argument:
>
> > format_ftable <- utils::getS3method("format", "ftable")
> > format_ftable(mytable)
>
> > -Kirill
>
> Well, I don't think it would fail as that does
>
> if (!inherits(x, "ftable"))
> stop("'x' must be an \"ftable\" object")
>
> and the OP did mention that his objects were flat tables.
>
> Note that the above is *good style* as opposed to the "bad"
> code I've seen so often in packages (and otherwise) which would
> use something like
>
> if(class(x) == "ftable") ## really really bad
>
> because that code will work incorrectly for objects with S3
> class attribute, say c("myFtable", "ftable")
>
> Martin
>
> ______________________________________________
> R-package-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
[[alternative HTML version deleted]]
More information about the R-package-devel
mailing list