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

Jeff Ryan jeff.a.ryan at gmail.com
Tue May 5 20:11:46 CEST 2009


Luis,

Thanks for the report.  That is indeed a bug.  I have fixed on R-forge.

While Next and Lag still work, I am moving to do away with them now
that there is a specific lag.xts method in xts.

lag(x, -1) does the same as Next(x), and is a bit more R-like (which
is a very good thing).

Thanks
Jeff


On Tue, May 5, 2009 at 12:46 PM, Luis Torgo <ltorgo at inescporto.pt> wrote:
> 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
>
> _______________________________________________
> 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