[Rd] setOldClass("xts")

Xavier Faure-Miller xavier at 4ecap.com
Wed Nov 4 06:39:00 CET 2015


Hello,

I apologize that I am cross posting here after getting no answer from
my initial
question on stack overflow
<http://stackoverflow.com/questions/33492601/r-setoldclass-only-if-needed>.
I should certainly have posted it first here..


I am using 3 packages:

   - xts
   - quantmod
   - 'myPackage'

quantmod is creating a union class by doing:

setOldClass("xts");
setClassUnion("xtsORzoo", c("xts","zoo"))

In 'myPackage' I am also creating a union class by doing

setOldClass("xts");
setClassUnion("xtsOrNULL",members=c("xts", "NULL"))

I did not notice any issue until: Since version 3.2.2
<https://cran.r-project.org/doc/manuals/r-release/NEWS.html>, R is
displaying a warning as soon as I manipulate an object of class xts:

Found more than one class "xts" in cache; using the first, from
namespace 'quantmod'Found more than one class "xts" in cache; using
the first, from namespace 'quantmod'


Indeed in this case it seems we are creating 2 virtual class for xts, one
in package environement quantmod and one in package environment myPackage.
Each is extended by different unionClass.

1) is it a problem (appart from this annoying warning?)
2) Should I instead use

if (is.null(.Call(methods:::C_R_getClassFromCache, "xts",
methods:::.classTable))) setOldClass("xts")

So that I create the virtual class only of it has not been created by
someone else in another package (and by the way in this case quantmod
should do the same to avoid issues when packages are loaded in a different
order)

3) and finally, is it not a bug in getClass ? I would have expected it to
first try to get the class definition from the parent environment. The fact
that I get the warning shows that it searches all environements, finds 2
classes from 2 different environments and chooses arbitrarily.

Thank you

*Disclaimer:* This email does not constitute investment advice or counsel
or solicitation for investment of any product or fund. This email does not
constitute or form part of, and should not be construed as, any offer for
sale or subscription of, or any invitation to offer to buy or subscribe
for, any investments, nor should it or any part of it form the basis of, or
be relied on in any connection with, any contract or commitment whatsoever.
FOUR ELEMENTS CAPITAL expressly disclaims any and all responsibility for
any direct or consequential loss or damage of any kind whatsoever arising
directly or indirectly from: (i) the use of this email, (ii) reliance on
any information contained herein, (iii) any error, omission or inaccuracy
in any such information. This communication is confidential, may be
privileged and is meant only for the intended recipient.  If you are not
the intended recipient, please notify the sender by reply and delete this
message from your system.  Any unauthorised dissemination, distribution or
copying hereof is prohibited.

	[[alternative HTML version deleted]]



More information about the R-devel mailing list