[Rprotobuf-commits] r333 - pkg/inst/examples/HighFrequencyFinance

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Jul 17 20:11:51 CEST 2010


Author: edd
Date: 2010-07-17 20:11:51 +0200 (Sat, 17 Jul 2010)
New Revision: 333

Modified:
   pkg/inst/examples/HighFrequencyFinance/loadInR.r
Log:
add improved version, and now it even works


Modified: pkg/inst/examples/HighFrequencyFinance/loadInR.r
===================================================================
--- pkg/inst/examples/HighFrequencyFinance/loadInR.r	2010-07-17 18:07:00 UTC (rev 332)
+++ pkg/inst/examples/HighFrequencyFinance/loadInR.r	2010-07-17 18:11:51 UTC (rev 333)
@@ -33,16 +33,16 @@
     invisible(df)
 }
 
-betterUse <- function( file = "trades.pb" ){
-    readProtoFiles("trade.proto")
-    x <- read( trade.Trades, file )
+betterUse <- function(verbose=TRUE, file = "trades.pb") {
+    readProtoFiles("TradeData.proto")
+    x <- read( TradeData.Trades, "trades.pb")
     xl <- lapply( x$fill, as.list )
 
-     df <- data.frame(timestamp = sapply( xl, "[[", "timestamp" ),
-                      symbol    = sapply( xl, "[[", "symbol" ),
-                      price     = sapply( xl, "[[", "price" ),
-                      size      = sapply( xl, "[[", "size" )
-                      )
+    df <- data.frame(timestamp = sapply( xl, "[[", "timestamp" ),
+                     symbol    = sapply( xl, "[[", "symbol" ),
+                     price     = sapply( xl, "[[", "price" ),
+                     size      = sapply( xl, "[[", "size" )
+                     )
     df[,1] <- as.POSIXct(df[,1], origin="1970-01-01")
     if (verbose) print(summary(df))
     invisible(df)
@@ -93,19 +93,20 @@
     invisible(NULL)
 }
 
+suppressMessages(library(stats))
 suppressMessages(library(RProtoBuf))
 suppressMessages(library(rbenchmark))
 
 #moduled()
-#q()
+
 dyn.load("protoLoadForR.so")
 
 print(benchmark(basicUse  = basicUse(FALSE),
-                betterUs  = basicUse(FALSE),
+                betterUs  = betterUse(FALSE),
                 preAlloc  = preAlloc(FALSE),
                 compiled  = compiled(FALSE),
                 order = "elapsed",
                 columns = c("test", "replications", "elapsed", "relative", "user.self", "sys.self"),
-                replications  = 1))
+                replications  = 3))
 
 



More information about the Rprotobuf-commits mailing list