6

Please, put this data structure into R in order to reproduce my example:

dX <- structure(c(3272.1, 3271.48, 3281.03, 3267.08, 3260.65, NA, 1616.3, 
1620.1, 1639.9, 1637.4, 1669.6, 1662.2, 528.385, 529.268, 531.022, 
532.424, NA, NA), .indexTZ = "", class = c("xts", "zoo"), .indexCLASS = c("POSIXct", 
"POSIXt"), tclass = c("POSIXct", "POSIXt"), tzone = "", index = structure(c(1345147200, 
1345406400, 1345492800, 1345579200, 1345665600, 1345752000), tzone = "", tclass = c("POSIXct", 
"POSIXt")), .Dim = c(6L, 3L), .Dimnames = list(NULL, c("M1WO.Index", 
"GC1.COMB.Comdty", "JGAGGUSD.Index")))

Now try this code:

library(PerformanceAnalytics)
library(quantmod)
library(timeSeries)
charts.PerformanceSummary(R = dX)

and get this error:

Error in UseMethod("time<-") :
  no applicable method for 'time<-' applied to an object of class "c('xts', 'zoo')"

I guess the issue is about the datas whose class = c("xts, "zoo"), but I do not understand why it reads those datas in that format and how may I coerce it to a simple xts object.

How could I solve this issue?

My system:

R version 2.15.1 (2012-06-22)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
 [1] timeSeries_2160.94           timeDate_2160.95            
 [3] quantmod_0.3-17              TTR_0.21-1                  
 [5] Defaults_1.1-1               PerformanceAnalytics_1.0.4.4
 [7] xts_0.8-6                    zoo_1.7-7                   
 [9] rcom_2.2-5                   rscproxy_2.0-5              

loaded via a namespace (and not attached):
[1] fBasics_2160.81  fGarch_2110.80.1 grid_2.15.1      lattice_0.20-6  
[5] MASS_7.3-18      stabledist_0.6-4 tools_2.15.1  

When I load packages, I get the following:

Loading required package: zoo

Attaching package: ‘zoo’

The following object(s) are masked from ‘package:base’:

    as.Date, as.Date.numeric

Loading required package: timeDate

Attaching package: ‘timeDate’

The following object(s) are masked from ‘package:PerformanceAnalytics’:

    kurtosis, skewness

Attaching package: ‘timeSeries’

The following object(s) are masked from ‘package:zoo’:

    time<-

According to the error messagge, I guess the issue comes when attaching timeSeries and time<- is masked from package:zoo, which I do not really know what it does mean and how to deal with.

Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
user1621969
  • 63
  • 1
  • 4
  • Have you loaded the package `xts` ? – Pop Aug 24 '12 at 08:06
  • Of course I have :) I've just added another command line to my example code, in order to load `quantmod` and so load `xts` as well. – user1621969 Aug 24 '12 at 08:09
  • Consider that `class(as.xts(dX))` still returns an `"xts" "zoo"` object, while I would like to omit the `zoo` component. – user1621969 Aug 24 '12 at 08:12
  • I don't get an error with your code. What is the output of `sessionInfo()`? – Roland Aug 24 '12 at 09:22
  • It's too long to be attached here. What's the field you're interested in? `R version 2.15.1 (2012-06-22) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252` – user1621969 Aug 24 '12 at 09:33
  • `attached base packages: [1] stats graphics grDevices datasets utils methods base other attached packages: [1] timeSeries_2160.94 timeDate_2160.95 [3] quantmod_0.3-17 TTR_0.21-1 [5] Defaults_1.1-1 PerformanceAnalytics_1.0.4.4 [7] xts_0.8-6 zoo_1.7-7 [9] rcom_2.2-5 rscproxy_2.0-5 ` – user1621969 Aug 24 '12 at 09:35
  • `loaded via a namespace (and not attached): [1] fBasics_2160.81 fGarch_2110.80.1 grid_2.15.1 lattice_0.20-6 [5] MASS_7.3-18 stabledist_0.6-4 tools_2.15.1 ` – user1621969 Aug 24 '12 at 09:35
  • You can add it as an edit to your question. I see you have loaded some packages that are not loaded by your code. Do you get the error, if you run your code in a new R session? Did you get a warning that functions were masked, when loading packages (e.g. timeSeries_2160.94)? – Roland Aug 24 '12 at 09:40
  • I get the same error in a new session. I follow your suggestment and edit my question to show you what's masked when I load packages. Just a moment... – user1621969 Aug 24 '12 at 09:46

1 Answers1

10

The problem is package timeSeries. Loading it gives the following warning:

Attaching package: ‘timeSeries’

The following object(s) are masked from ‘package:zoo’:

    time<-

You can detach the package for using charts.PerformanceSummary and than load it again:

detach('package:timeSeries')
detach('package:timeDate') # since it masks statistical functions
charts.PerformanceSummary(R = dX)
library(timeSeries)
Roland
  • 127,288
  • 10
  • 191
  • 288
  • Thank you, Roland. Please, assume I **have to** load `timeSeries`: how may I deal with this problem? – user1621969 Aug 24 '12 at 09:53
  • Yep! What else? :) Thank you very much – user1621969 Aug 24 '12 at 10:08
  • @user1621969, You can patch your version of PerformanceAnalytics. Change line 237 of chart.TimeSeries.R to `rownames = as.Date(xts:::time.xts(y))`. Then, rebuild and install. – GSee Aug 24 '12 at 12:50
  • @user1621969: you can also load timeSeries first, then PerformanceAnalytics. That will ensure timeSeries and timeDate are further down the search path than xts/zoo, so the xts/zoo `time<-` methods will be found first. – Joshua Ulrich Aug 24 '12 at 12:51
  • Thanks to Brian for applying a patch quickly. You can follow the instructions [here](http://stackoverflow.com/questions/11105131/cannot-install-r-forge-package-using-install-packages) to checkout, build, and install the latest version of PerformanceAnalytics. – GSee Aug 24 '12 at 13:07