[R-SIG-Finance] xts and Sys.time() - very stange behaviour

soren wilkening me at censix.com
Wed Aug 1 20:08:58 CEST 2012


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
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)

 [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           

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
ordertime1 <- t0 
Things seem to work fine. That however is not a solution since the addition
is an essential component here.

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.

More information about the R-SIG-Finance mailing list