[R-SIG-Finance] Problem with subsetting in xts package

Luis Torgo ltorgo at inescporto.pt
Tue May 5 19:46:59 CEST 2009


Dear All,

I met with a problem that I think it's being caused by a problem in the 
sub-setting methods in xts.

I found this problem because I was using the Next() function from 
quantmod as follows:

 > x <- GSPC$GSPC.Adjusted["200904/"]
 > Delt(x)
           Delt.1.arithmetic
2009-04-01                NA
2009-04-02       0.028727129
2009-04-03       0.009731777
2009-04-06      -0.008332344
2009-04-07      -0.023854551
...
 > Next(x)
Error in `[.xts`(x, -(0:k), ) :
  only zeros may be mixed with negative subscripts

I found it odd as k is by default 1 and thus "-(0:k)" should be
 > -(0:1)
[1]  0 -1

After a bit of debugging I think I've isolated the problem at the 
`[.xts` code namely,

`.subset.xts` <- `[.xts` <-
function(x, i, j, drop = FALSE, ...)
   ...
   # test for negative subscripting in i
    if (!missing(i) && is.numeric(i) ) {
      if(any(i < 0)) {
        if(!all(i < 0))
          stop('only zeros may be mixed with negative subscripts')
   ...
in file "xts.methods.R".

I think it should be:
        if(!all(i <= 0))
instead...

Or am I missing something?


My sysinfo:
 > R.version
               _                          
platform       i486-pc-linux-gnu          
arch           i486                       
os             linux-gnu                  
system         i486, linux-gnu            
status                                    
major          2                          
minor          9.0                        
year           2009                       
month          04                         
day            17                         
svn rev        48333                      
language       R                          
version.string R version 2.9.0 (2009-04-17)

The xts version is 0.6-4
Thanks,
Luis

-- 
Luis Torgo
   FC/LIAAD - INESC Porto, LA    Phone : (+351) 22 339 20 93
   University of Porto           Fax   : (+351) 22 339 20 99
   R. de Ceuta, 118, 6o          email : ltorgo at liaad.up.pt
   4050-190 PORTO - PORTUGAL     WWW   : http://www.liaad.up.pt/~ltorgo



More information about the R-SIG-Finance mailing list