[R-SIG-Finance] xts and Sys.time() - very stange behaviour
Jeff Ryan
jeff.a.ryan at gmail.com
Wed Aug 1 20:16:37 CEST 2012
2.12! It's 2012 man, not 2010!!!! ;-)
Joking aside, I can't replicate using a more modern version of all the tools:
> ob[ key ]
[,1] [,2]
2012-08-01 13:13:32.638 "aaaa" "bbbb"
> sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] xts_0.8-7 zoo_1.7-6
loaded via a namespace (and not attached):
[1] grid_2.15.0 lattice_0.19-17
On Wed, Aug 1, 2012 at 1:08 PM, soren wilkening <me at censix.com> wrote:
> require(xts)
> options(digits.secs=3)
>
> ob <- xts(as.matrix(t(c("aa", "bb"))), order.by = as.POSIXct("2000-01-31
> 13:45:02.437") )
> #get t0 as an arbitrary timestamp, with subsecond accuracy, truncated to
> microseconds
> t0 <- as.POSIXct( strftime(Sys.time(), "%Y-%m-%d %H:%M:%OS3") )
> #add a microsecond
> ordertime1 <- t0 + 1e-3
> neworder <- xts(as.matrix(t(c('aaaa', 'bbbb'))), order.by = (ordertime1))
> ob <- rbind(ob,neworder)
> key <- as.character(index(neworder))
>
> #returns 1 row
> ob[ "2000-01-31 13:45:02.437" ]
>
> # sometimes returns nothing ???
> ob[ key ]
>
>
>
>
>
> The last line should normally return the last row of 'ob'. If I run the
> entire code snippet about 5 times
> I get at least one run where it returns an empty row. But that should never
> happen.?! Here is my sessionInfo.
>
> 1> sessionInfo()
> R version 2.12.0 (2010-10-15)
> Platform: i686-pc-linux-gnu (32-bit)
>
> locale:
> [1] LC_CTYPE=en_US.utf8 LC_NUMERIC=C
> [3] LC_TIME=en_US.utf8 LC_COLLATE=en_US.utf8
> [5] LC_MONETARY=C LC_MESSAGES=en_US.utf8
> [7] LC_PAPER=en_US.utf8 LC_NAME=C
> [9] LC_ADDRESS=C LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
>
> other attached packages:
> [1] xts_0.7-6.9 zoo_1.7-0
>
> loaded via a namespace (and not attached):
> [1] grid_2.12.0 lattice_0.19-13
>
>
> I have just noticed that when I change the line:
> ordertime1 <- t0 + 1e-3
> to
> ordertime1 <- t0
> Things seem to work fine. That however is not a solution since the addition
> is an essential component here.
>
>
>
> -----
> http://censix.com
> --
> View this message in context: http://r.789695.n4.nabble.com/xts-and-Sys-time-very-stange-behaviour-tp4638714p4638728.html
> Sent from the Rmetrics mailing list archive at Nabble.com.
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
--
Jeffrey Ryan
jeffrey.ryan at lemnica.com
www.lemnica.com
More information about the R-SIG-Finance
mailing list