[R-SIG-Finance] how to use xts in setClass()

Jeff Ryan jeff.a.ryan at gmail.com
Tue Oct 27 16:29:39 CET 2009


In fact zoo doesn't work for me by default.  I think the issue is that
quantmod calls setOldClass for you (to use S3 as S4 slots).

library(zoo)
setClass("trader",representation(prices="zoo",indicator="zoo"))

[1] "trader"
Warning message:
In .completeClassSlots(ClassDef, where) :
  undefined slot classes in definition of "trader": prices(class
"zoo"), indicator(class "zoo")


Keeping the environment as clean as possibly (don't attach other
packages that can change the game) is the best way to find the issue.

library(xts)
setClass("trader",representation(prices="xts",indicator="xts"))

[1] "trader"
Warning message:
In .completeClassSlots(ClassDef, where) :
  undefined slot classes in definition of "trader": prices(class
"xts"), indicator(class "xts")


# have to call setOldClass ... this really should be setS3Class IMO,
as "Old" implies bad...

setOldClass("xts")
setClass("trader",representation(prices="xts",indicator="xts"))
[1] "trader"

getClass("trader")
Class "trader" [in ".GlobalEnv"]

Slots:

Name:     prices indicator
Class:       xts       xts

As may be evident from my previous work, I'd petition you not to use
S4 classes until S5 comes out ;)  quantmod is in the process of
removing all S4 objects, instead migrating to more powerful (though
slightly less OO style in some sense) functional closures.  Yes
_functional closures_...

One other point, the newest xts_0.6-8 from CRAN should be used now, as
there were some major improvements and bug fixes implemented in the
release.

Best,
Jeff

On Tue, Oct 27, 2009 at 5:22 AM, Wind <windspeedo99 at gmail.com> wrote:
> I wonder how to  use xts in setClass().   It seems that zoo is OK.
> Thanks.
>
> Wind
>
>
>> library(quantmod)
> Loading required package: xts
> Loading required package: zoo
>
> Attaching package: 'zoo'
>
>
> The following object(s) are masked from package:base :
>
>  as.Date.numeric
>
> xts now requires a valid TZ environment variable to be set
>  your current TZ:CST-8
> Loading required package: Defaults
> Loading required package: TTR
>> setClass("trader",representation(prices="zoo",indicator="zoo"))
> [1] "trader"
>> setClass("trader",representation(prices="xts",indicator="xts"))
> [1] "trader"
> Warning message:
> In .completeClassSlots(ClassDef, where) :
>  undefined slot classes in definition of "trader": prices(class "xts"),
> indicator(class "xts")
>
>> sessionInfo()
> R version 2.9.2 (2009-08-24)
> i386-pc-mingw32
>
> locale:
> LC_COLLATE=Chinese (Simplified)_People's Republic of
> China.936;LC_CTYPE=Chinese (Simplified)_People's Republic of
> China.936;LC_MONETARY=Chinese (Simplified)_People's Republic of
> China.936;LC_NUMERIC=C;LC_TIME=English_United States.1252
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] quantmod_0.3-11 TTR_0.20-1      Defaults_1.1-1  xts_0.6-7
> [5] zoo_1.5-8
>
> loaded via a namespace (and not attached):
> [1] grid_2.9.2      lattice_0.17-25
>>
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>



-- 
Jeffrey Ryan
jeffrey.ryan at insightalgo.com

ia: insight algorithmics
www.insightalgo.com



More information about the R-SIG-Finance mailing list