[Rprotobuf-commits] r339 - papers/user2010

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Jul 18 17:53:30 CEST 2010


Author: edd
Date: 2010-07-18 17:53:30 +0200 (Sun, 18 Jul 2010)
New Revision: 339

Added:
   papers/user2010/build.R
   papers/user2010/setup.tex
   papers/user2010/slides.Rnw
Log:
first shot at slides for Thursday's presentation


Added: papers/user2010/build.R
===================================================================
--- papers/user2010/build.R	                        (rev 0)
+++ papers/user2010/build.R	2010-07-18 15:53:30 UTC (rev 339)
@@ -0,0 +1,28 @@
+#!/usr/bin/r
+
+require( utils )
+require( highlight )
+require( Rcpp )
+require( inline )
+
+basefile <- "slides"
+rnwfile <- paste(basefile, ".Rnw", sep="")
+texfile <- paste(basefile, ".tex", sep="")
+
+driver <- HighlightWeaveLatex( boxes = TRUE )
+Sweave( rnwfile, driver = driver )
+tex <- readLines( texfile )
+target <- "\\begin{minipage}[b]{.9\\textwidth}%"
+tex[ tex == target ] <- "\\begin{minipage}[b]{.95\\textwidth}%"
+
+target <- "\\vspace{1em}\\noindent\\fbox{\\begin{minipage}{0.9\\textwidth}"
+tex[ tex == target ] <- "\\vspace{1em}\\noindent\\fcolorbox{highlightBorder}{highlightBg}{\\begin{minipage}{0.95\\textwidth}"
+
+endboxes <- grep( "^\\\\mbox", tex )
+tex[ endboxes - 1 ] <- sprintf( "%s \\mbox{}",
+	sub( "\\\\\\\\$", "", tex[ endboxes - 1 ] ) )
+tex[ endboxes ] <- ""
+
+writeLines( tex, texfile )
+tools::texi2dvi( texfile, pdf = TRUE, clean = TRUE )
+


Property changes on: papers/user2010/build.R
___________________________________________________________________
Added: svn:executable
   + *

Added: papers/user2010/setup.tex
===================================================================
--- papers/user2010/setup.tex	                        (rev 0)
+++ papers/user2010/setup.tex	2010-07-18 15:53:30 UTC (rev 339)
@@ -0,0 +1,209 @@
+
+\mode<presentation>
+{
+  %\usetheme[secheader]{Madrid} % nice (once my coloroverrides are sorted out)
+  %\usetheme{AnnArbor}	% nice!	
+  %\usetheme{Malmoe}	% nice!	
+  \usetheme{Warsaw}	% nice!	
+
+  %\usetheme[secheader]{Boadilla} % ok
+  %\usecolortheme{whale}
+  %\usecolortheme{orchid}
+}
+
+% If you wish to uncover everything in a step-wise fashion, uncomment the following command: 
+%\beamerdefaultoverlayspecification{<+->}
+
+% Delete this, if you do not want the table of contents to pop up at
+% the beginning of each subsection (or section)
+% edd: Does not work in handout mode, and we have too many section/subsections
+%\AtBeginSection[]{%
+%  \begin{frame}<beamer>%
+%    %\tiny
+%    \frametitle{Outline}%
+%    \tableofcontents[currentsection]%
+%  \end{frame}
+%}
+
+%\AtBeginSubsection[]{%
+%   \begin{frame}
+%     \frametitle{Outline}
+%     \tableofcontents[currentsection,currentsubsection]
+%   \end{frame}
+%}
+
+% Delete this, if you do not want the table of contents to pop up at
+% the beginning of each subsection (or section)
+% edd: Does not work in handout mode, and we have too many section/subsections
+\AtBeginSection[]{%
+  \begin{frame}<beamer>%
+    \frametitle{Outline}%
+    %\tableofcontents[currentsection]%
+    \tableofcontents[currentsection,hideothersubsections]%
+  \end{frame}
+}
+ 
+%\AtBeginSection[] % Do nothing for \section* 
+%{ \begin{frame}<beamer>
+%    \frametitle{Outline}
+%    {%\footnotesize 
+%      \begin{columns}
+%        \begin{column}{0.5\textwidth}
+%          \tableofcontents[currentsection,sections={1-2}]
+%        \end{column}
+%        \begin{column}{0.5\textwidth}
+%          \tableofcontents[currentsection,sections={3-4}]
+%        \end{column}
+%      \end{columns}
+%    } 
+%  \end{frame} 
+%}
+
+\newcommand{\MedSkip}{\medskip \par} % add \pause if desired 
+\newcommand{\SmallSkip}{\smallskip} % add \pause if desired 
+
+\usepackage[english]{babel}   	% or whatever
+\usepackage[latin1]{inputenc}	% or whatever
+\usepackage{times}
+\usepackage[T1]{fontenc}	% Or whatever. Note that the encoding and the 
+				% font should match. If T1 does not look
+                                % nice, try deleting the line with the fontenc.
+%\usepackage{highlight}
+
+\usepackage{booktabs}
+
+\usepackage{listings}
+\lstset{ %
+  language=R,                   % choose the language of the code
+  basicstyle=\scriptsize,       % the size of the fonts that are used for the code
+  numbers=left,                 % where to put the line-numbers
+  numberstyle=\tiny,            % the size of the fonts that are used for the line-numbers
+  stepnumber=1,                 % the step between two line-numbers. If it's 1 each line will be numbered
+  numbersep=5pt,                % how far the line-numbers are from the code
+  backgroundcolor=\color{white},% choose the background color. You must add \usepackage{color}
+  showspaces=false,             % show spaces adding particular underscores
+  showstringspaces=false,       % underline spaces within strings
+  showtabs=false,               % show tabs within strings adding particular underscores
+  frame=single,                 % adds a frame around the code
+  tabsize=2,                    % sets default tabsize to 2 spaces
+  captionpos=b,                 % sets the caption-position to bottom
+  breaklines=true,              % sets automatic line breaking
+  breakatwhitespace=false,      % sets if automatic breaks should only happen at whitespace
+  escapeinside={\%*}{*)}        % if you want to add a comment within your code
+}
+
+\hypersetup{                  		% beamer colors taken from elsewhere
+  hyperindex,%				% works with the beetle colour scheme
+  colorlinks,%
+  linktocpage,%
+  plainpages=true,%
+  linkcolor=myOrange,%
+  citecolor=myDarkGrey,%
+  urlcolor=myDarkBlue,%
+  pdfstartview=Fit,%
+  pdfview={XYZ null null null}%
+}
+%\hypersetup{                  		% beamer colors taken from elsewhere
+%  hyperindex,%				% works with the beetle colour scheme
+%  colorlinks%
+%  linktocpage,%
+%  plainpages=false,%
+%  linkcolor=eddBlue,%
+%  citecolor=eddDarkGrey,%
+%  urlcolor=eddDarkBlue,%
+%  pdfstartview=Fit,%
+%  pdfview={XYZ null null null}%
+%}
+
+\RequirePackage{color}
+\definecolor{Red}{rgb}{0.7,0,0}
+\definecolor{myOrange}{rgb}{0.8,0.5,0.0}
+\definecolor{myBlue}{rgb}{0.0,0.0,0.4}
+\definecolor{myDarkBlue}{rgb}{0.1,0.1,0.4}
+\definecolor{myDarkGrey}{rgb}{0.15,0.15,0.15}
+% Doug's
+\definecolor{Sinput}{rgb}{0,0,0.56}
+\definecolor{Scode}{rgb}{0,0,0.56}
+\definecolor{Soutput}{rgb}{0.56,0,0}
+% 
+\definecolor{Cmdinput}{rgb}{0,0,0.44}
+\definecolor{Cmdoutput}{rgb}{0.44,0,0}
+\definecolor{Cppinput}{rgb}{0.15,0.15,0.15}
+
+%% from Doug, but mod'ed \R to use hyperref
+\RequirePackage{fancyvrb}
+\RequirePackage{xspace}
+\RequirePackage{paralist}
+% \newenvironment{Schunk}{\par\begin{minipage}{\textwidth}}{\end{minipage}}
+% \DefineVerbatimEnvironment{Sinput}{Verbatim}{formatcom={\color{Sinput}},fontsize=\scriptsize}
+% \DefineVerbatimEnvironment{Soutput}{Verbatim}{formatcom={\color{Soutput}},fontsize=\scriptsize}
+% \DefineVerbatimEnvironment{Scode}{Verbatim}{formatcom={\color{Scode}},fontsize=\small}
+% \DefineVerbatimEnvironment{Cmdinput}{Verbatim}{formatcom={\color{Cmdinput}},fontsize=\scriptsize}
+% \DefineVerbatimEnvironment{Cmdoutput}{Verbatim}{formatcom={\color{Cmdoutput}},fontsize=\scriptsize}
+% \DefineVerbatimEnvironment{Cppinput}{Verbatim}{formatcom={\color{Cppinput}},fontsize=\small}
+
+% -- not \small 
+\newcommand{\smallcode}[1]{{\color{Sinput}\small\texttt{#1}}}
+\newcommand{\code}[1]{{\color{Sinput}\texttt{#1}}}
+\newcommand{\Emph}[1]{\emph{\color{Scode}#1}}   
+%\newcommand{\R}{\href{http://www.r-project.org}{\Emph{R}\xspace}}   %% ? sing \emph upsets beamer inside \href
+\newcommand{\R}{\href{http://www.r-project.org}{\textsf{R}\xspace}}
+\newcommand{\Rns}{\href{http://www.r-project.org}{\textsf{R}}}
+
+% two old defintions
+%\newcommand{\code}[1]{\texttt{#1}}
+\newcommand{\screenshot}[1]{\centerline{\includegraphics[height=7.8cm,transparent]{#1}}}  % 7.8in
+
+
+% If you have a file called "university-logo-filename.xxx", where xxx
+% is a graphic format that can be processed by latex or pdflatex,
+% resp., then you can add a logo as follows:
+% NB transparent in Adobe but not in kpdf
+% \pgfdeclareimage[height=0.6cm]{useR-logo}{figures/useR}
+% \logo{\pgfuseimage{useR-logo}}
+
+% \pgfdeclareimage[height=1cm]{debian-logo}{figures/debian-openlogo-100}
+% \logo{\pgfuseimage{debian-logo}}
+
+%% code from
+%% http://old.nabble.com/Two-logos-instead-of-the-default-one-td16000584.html
+%% and posted by Matthew Leingang
+%\pgfdeclareimage[height=0.5cm]{msri-logo}{msri-logo-clipped} 
+% put MSRI logo in bottom left 
+%% \setbeamertemplate{sidebar left}{% 
+%%    \vfill% 
+%%    \rlap{\hskip0.1cm 
+%%      \href{http://www.debian.org}{\pgfuseimage{debian-logo}}}% 
+%%    %\vskip2pt% 
+%%    %\llap{\usebeamertemplate***{navigation symbols}\hskip0.1cm}% 
+%%    \vskip2pt% 
+%% } 
+
+%% from highlight
+% Style definition file generated by highlight 2.7, http://www.andre-simon.de/ 
+
+% Highlighting theme definition: 
+
+% \newcommand{\hlstd}[1]{\textcolor[rgb]{0,0,0}{#1}}
+% \newcommand{\hlnum}[1]{\textcolor[rgb]{0,0,0}{#1}}
+% \newcommand{\hlesc}[1]{\textcolor[rgb]{0.74,0.55,0.55}{#1}}
+% \newcommand{\hlstr}[1]{\textcolor[rgb]{0.74,0.55,0.55}{#1}}
+% \newcommand{\hldstr}[1]{\textcolor[rgb]{0.74,0.55,0.55}{#1}}
+% \newcommand{\hlslc}[1]{\textcolor[rgb]{0.67,0.13,0.13}{\it{#1}}}
+% \newcommand{\hlcom}[1]{\textcolor[rgb]{0.67,0.13,0.13}{\it{#1}}}
+% \newcommand{\hldir}[1]{\textcolor[rgb]{0,0,0}{#1}}
+% \newcommand{\hlsym}[1]{\textcolor[rgb]{0,0,0}{#1}}
+% \newcommand{\hlline}[1]{\textcolor[rgb]{0.33,0.33,0.33}{#1}}
+% \newcommand{\hlkwa}[1]{\textcolor[rgb]{0.61,0.13,0.93}{\bf{#1}}}
+% \newcommand{\hlkwb}[1]{\textcolor[rgb]{0.13,0.54,0.13}{#1}}
+% \newcommand{\hlkwc}[1]{\textcolor[rgb]{0,0,1}{#1}}
+% \newcommand{\hlkwd}[1]{\textcolor[rgb]{0,0,0}{#1}}
+% \definecolor{bgcolor}{rgb}{1,1,1}
+
+
+
+
+%%% Local Variables: 
+%%% mode: latex
+%%% TeX-master: "introhighperfR"
+%%% End: 


Property changes on: papers/user2010/setup.tex
___________________________________________________________________
Added: svn:executable
   + *

Added: papers/user2010/slides.Rnw
===================================================================
--- papers/user2010/slides.Rnw	                        (rev 0)
+++ papers/user2010/slides.Rnw	2010-07-18 15:53:30 UTC (rev 339)
@@ -0,0 +1,440 @@
+\documentclass[compress]{beamer}
+%\usepackage{beamerthemebars}
+%\usepackage{pgfpages}
+%\pgfpagesuselayout{2 on 1}[letterpaper,border shrink=5mm]
+%\pgfpagesuselayout{4 on 1}[letterpaper,border shrink=5mm]
+%\pgfpagesuselayout{2 on 1}[a4,border shrink=5mm]
+
+\include{setup}  %% has all definitions etc
+\newcommand{\Pause}{\pause}
+%\newcommand{\Pause}{}
+% If you wish to uncover everything in a step-wise fashion, uncomment the following command:
+%\beamerdefaultoverlayspecification{<+->}
+
+\newcommand{\proglang}[1]{\textsf{\color{myDarkBlue} #1}}
+\newcommand{\pkg}[1]{{\fontseries{b}\selectfont #1}}
+
+\title[\pkg{RProtoBuf}: Protocol Buffers for R  @ \textsl{useR! 2010}]{\pkg{RProtoBuf}: Protocol Buffers for R}
+\author[Romain Fran\c{c}ois and Dirk Eddelbuettel]{Romain Fran\c{c}ois\inst{1} \and Dirk Eddelbuettel\inst{2} }
+\institute[R Enthusiasts and Debian]{
+  \inst{1}%
+  R Enthusiasts
+  \and
+  \inst{2}
+  Debian Project
+}
+
+\date[\textsl{useR! 2010}]{ \textsl{useR! 2010} \\
+  National Institute of Standards and Technology (NIST)\\
+  Gaithersburg, Maryland, USA}
+
+%\usebackgroundtemplate{\includegraphics[width=\paperwidth]{images/millau-bright.jpg}}
+
+\begin{document}
+
+%\usebackgroundtemplate{\includegraphics[width=\paperwidth]{images/bridge-2.png}}
+%\setbeamertemplate{navigation symbols}{}
+
+\begin{frame}
+  \titlepage
+\end{frame}
+
+%\usebackgroundtemplate{\includegraphics[width=\paperwidth]{images/bridge-white.png}}
+\begin{frame}
+  \frametitle{Outline}
+  \tableofcontents[hideallsubsections]
+\end{frame}
+
+\section{Protocol Buffers}
+
+\subsection{Overview}
+
+\begin{frame}
+  \frametitle{Brief Description}
+  \framesubtitle{FIXME ?}
+
+  \begin{itemize}
+    \item Google's Protocol Buffers are a flexible, efficient, automated mechanism for
+      serializing structured data---think XML, but smaller, faster, and simpler.
+    \item Users define the data structures in a \texttt{proto} file, and then
+      use special generated source code.
+    \item This permits to easily write and read structured data to and from a
+      variety of data streams, and using a variety of officially supported
+      languages--- \proglang{Java}, \proglang{C++}, or \proglang{Python}.
+    \item Or one can use third-party implementations for
+      languages such as \proglang{C\#}, \proglang{Perl}, \proglang{Ruby},
+      \proglang{Haskell}, and now \proglang{R} via the \pkg{RProtoBuf} package.
+  \end{itemize}
+\end{frame}
+
+\subsection{Example}
+
+\begin{frame}
+  \frametitle{Example \texttt{proto} file from Tutorial}
+  %\framesubtitle{FIXME ?}
+
+  \begin{footnotesize}
+<<lang=cpp>>=
+package tutorial;
+message Person {
+ required string name = 1;
+ required int32 id = 2;        // Unique ID number for person.
+ optional string email = 3;
+ enum PhoneType {
+   MOBILE = 0; HOME = 1; WORK = 2;
+ }
+ message PhoneNumber {
+   required string number = 1;
+   optional PhoneType type = 2 [default = HOME];
+ }
+ repeated PhoneNumber phone = 4;
+}
+// Our address book file is just one of these.
+message AddressBook {
+  repeated Person person = 1;
+}
+@
+\end{footnotesize}
+\end{frame}
+
+\begin{frame}
+  \frametitle{Example C++ usage}
+
+  \begin{footnotesize}
+<<lang=cpp>>=
+#include "addressbook.pb.h"
+using namespace std;
+
+// Iterates though all people in the AddressBook
+// and prints info about them.
+void ListPeople(const tutorial::AddressBook& address_book) {
+  for (int i=0; i < address_book.person_size(); i++) {
+    const tutorial::Person& person =
+        address_book.person(i);
+
+    cout << "Person ID: " << person.id() << endl;
+    cout << "  Name: " << person.name() << endl;
+    if (person.has_email()) {
+      cout << "  E-mail address: "
+           << person.email() << endl;
+    }
+@
+\end{footnotesize}
+\end{frame}
+
+\begin{frame}
+  \frametitle{Example C++ usage (cont.)}
+
+  \begin{footnotesize}
+<<lang=cpp>>=
+    for (int j = 0; j < person.phone_size(); j++) {
+      const tutorial::Person::PhoneNumber
+         &phone_number = person.phone(j);
+
+      switch (phone_number.type()) {
+        case tutorial::Person::MOBILE:
+          cout << "  Mobile phone #: ";
+          break;
+        case tutorial::Person::HOME:
+          cout << "  Home phone #: ";
+          break;
+        case tutorial::Person::WORK:
+          cout << "  Work phone #: ";
+          break;
+      }
+      cout << phone_number.number() << endl;
+    }
+  }
+}
+@
+\end{footnotesize}
+
+\end{frame}
+
+\section{RProtoBuf}
+
+\subsection{Overview}
+
+\begin{frame}
+  \frametitle{Brief Description}
+  \framesubtitle{FIXME !!}
+
+  \begin{itemize}
+  \item The \pkg{RProtoBuf} package implements \proglang{R} bindings to the
+    \proglang{C++} protobuf library from Google.
+  \item \pkg{RProtoBuf} uses features of the
+    protocol buffer library to support creation, manipulation, parsing and
+    serialization of protocol buffers messages.
+  \item Taking advantage of facilities
+    in the \pkg{Rcpp} package, \pkg{RProtoBuf} uses S4 classes and external
+    pointers to expose objects that look and feel like standard \proglang{R}
+    lists, yet are managed by the underlying C++ library.
+  \item These objects also
+    conform to the language-agnostic definition of the message type allowing
+    access to their content from other supported languages.
+  \end{itemize}
+\end{frame}
+
+% \begin{frame}
+%   \frametitle{Brief Description}
+%   \framesubtitle{FIXME !!}
+%   As the protocal buffers library does not offer any built-in support
+%   for networked access to protocol buffer streams, we intend to take
+%   advantage on ongoing changes to the \proglang{R} system to expose a native
+%   \proglang{R} server. This is work-in-progress, but we hope to be able to
+%   report on this at the conference.
+% \end{frame}
+
+\subsection{Example}
+\begin{frame}
+  \frametitle{Example \texttt{proto} file for Financial Data}
+
+  \begin{small}
+<<lang=cpp>>=
+// Namespace
+package TradeData;
+
+// A simple Fill, ie a completed trade
+message Fill {
+  required double timestamp = 1;
+  required string symbol = 2;
+  required double price = 3;
+  required int32 size = 4;
+}
+
+// A sequence of Fills
+message Trades {
+  repeated Fill fill = 1;
+}
+@
+\end{small}
+
+\tiny See \texttt{inst/examples/HighFrequencyFinance/} in the \pkg{RProtoBuf} package.
+\end{frame}
+
+
+\subsection{Writer}
+\begin{frame}
+  \frametitle{Example C++ data creator}
+
+% #include "TradeData.pb.h"       // auto-generated ProtoBuffer data structure accessor
+% #include <iostream>
+% #include <fstream>
+
+% #define MATHLIB_STANDALONE 1    // so that we get set_seed()
+% #include <Rmath.h>              // to use R's RNGs and random distribution functions
+
+%    // Verify that the version of the library that we linked against is
+%    // compatible with the version of the headers we compiled against.
+%    GOOGLE_PROTOBUF_VERIFY_VERSION;
+
+  \begin{tiny}
+<<lang=cpp>>=
+int main(int argc, char **argv) {
+  const char* pbfile = "trades.pb";
+  const int N = 1000;
+  set_seed(123, 456);
+  double tstamp = 1277973000;     // 2010-07-01 08:30:00
+  double tprice = 100.0;          // gotta start somewhere
+  char sym[] = "ABC";
+  TradeData::Trades tr;
+  for (int i=0; i<N; i++) {
+    TradeData::Fill *fill = tr.add_fill();
+    tstamp += runif(0.000, 0.100);
+    tprice += round(rt(5) * 0.01 * 100)/100;
+    int tsize = 100 + round(runif(0,9))*100;
+    fill->set_timestamp(tstamp);
+    fill->set_price(tprice);
+    fill->set_symbol(sym);
+    fill->set_size(tsize);
+  }
+  std::fstream output(pbfile, std::ios::out | std::ios::binary);
+  if (!tr.SerializeToOstream(&output)) {
+      std::cerr << "Failed to write data." << std::endl;
+      return -1;
+  }
+  return 0;
+}
+
+@
+\end{tiny}
+\tiny See \texttt{inst/examples/HighFrequencyFinance/protoCreate.cpp}
+\end{frame}
+
+\begin{frame}
+  \frametitle{Extensibility}
+
+  We could add this to the \texttt{proto} file:
+
+  \begin{small}
+<<lang=cpp>>=
+ enum exchType {
+   NYSE = 0; NASDAQ = 1; ARCS = 2; BATS = 3;
+ }
+ optional exchType exchange = 5 [default = NYSE];
+@
+
+  \begin{quote}
+    If you want your new buffers to be backwards-compatible, and your old
+    buffers to be forward-compatible [...]:
+    \begin{itemize}
+    \item you must not change the tag [...] of any existing fields.
+    \item you must not add or delete any required fields.
+    \item you may delete optional or repeated fields.
+    \item you may add new optional or repeated fields but you must use fresh tag numbers [...]
+    \end{itemize}
+  \end{quote}
+  See \url{http://code.google.com/apis/protocolbuffers/docs/cpptutorial.html}
+\end{small}
+
+\end{frame}
+
+\subsection{R Readers}
+
+\begin{frame}
+  \frametitle{Example R reader: Simple}
+  \begin{footnotesize}
+<<lang=R>>=
+basicUse <- function(verbose=TRUE) {
+  readProtoFiles("TradeData.proto")
+  x <- read( TradeData.Trades, "trades.pb")
+  xl <- as.list(x)
+  df <- do.call(rbind,
+                lapply(as.list(xl$fill),
+                       function(.)
+                       as.data.frame(as.list(.))))
+  df[,1] <- as.POSIXct(df[,1], origin="1970-01-01")
+  if (verbose) print(summary(df))
+  invisible(df)
+}
+@
+\end{footnotesize}
+\tiny See \texttt{inst/examples/HighFrequencyFinance/loadInR.r}
+\end{frame}
+
+\begin{frame}
+  \frametitle{Example R reader: Smarter}
+  \begin{footnotesize}
+<<lang=R>>=
+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= as.POSIXct(sapply(xl,
+                      "[[", "timestamp" ),
+                      origin="1970-01-01"),
+                   symbol = sapply(xl,"[[","symbol"),
+                   price  = sapply(xl,"[[","price"),
+                   size   = sapply(xl,"[[","size"))
+  if (verbose) print(summary(df))
+  invisible(df)
+}
+@
+\end{footnotesize}
+\tiny See \texttt{inst/examples/HighFrequencyFinance/loadInR.r}
+\end{frame}
+
+\begin{frame}
+  \frametitle{Example R reader: Manual via Rcpp}
+  \begin{footnotesize}
+<<lang=R>>=
+compiled <- function(verbose=FALSE, file="trades.pb") {
+
+    stopifnot(file.exists(file))
+
+    df <- .Call("pbload", file);
+
+    if (verbose) print(summary(df))
+
+    invisible(df)
+}
+@
+\end{footnotesize}
+\tiny See \texttt{inst/examples/HighFrequencyFinance/loadInR.r}
+\end{frame}
+
+\begin{frame}
+  \frametitle{Example R reader: C++ support}
+  \begin{tiny}
+<<lang=C++>>=
+extern "C" SEXP pbload(SEXP b) {
+  std::string pbfile = Rcpp::as<std::string>(b);
+  TradeData::Trades tr;
+  std::fstream fs(pbfile.c_str(), std::ios::in | std::ios::binary);
+  if (!tr.ParseFromIstream(&fs)) {
+    std::cerr << "Trouble parsing..." << std::cout;
+    return R_NilValue;
+  }
+  int n = tr.fill_size();
+  Rcpp::DatetimeVector timestamp(n);
+  Rcpp::CharacterVector tsym(n);
+  Rcpp::NumericVector tprice(n);
+  Rcpp::IntegerVector tsize(n);
+  for (int i=0; i<n; i++) {
+    const TradeData::Fill &fill = tr.fill(i);
+    timestamp[i] = fill.timestamp();
+    tsym[i]      = fill.symbol();
+    tprice[i]    = fill.price();
+    tsize[i]     = fill.size();
+  }
+  return Rcpp::DataFrame::create(Rcpp::Named("times")  = timestamp,
+                                 Rcpp::Named("symbol") = tsym,
+                                 Rcpp::Named("price")  = tprice,
+                                 Rcpp::Named("size")   = tsize);
+}
+@
+\end{tiny}
+\tiny See \texttt{inst/examples/HighFrequencyFinance/protoModule.cpp}
+\end{frame}
+
+\begin{frame}[fragile]
+  \frametitle{Timing comparison}
+
+  Running the script \code{loadInR.r} from the aforementioned examples
+  directory in the \pkg{RProtoBuf} package:
+
+  \begin{table}
+    \small
+    \begin{tabular}{lrr}
+      \toprule
+      Version & Elapsed Time & Relative \\
+      \cmidrule{2-3}
+      Compiled & 0.006 & 1.0000 \\
+      betterUse & 0.138 & 23.0000 \\
+      basicUse & 4.606 & 767.6667 \\
+      \bottomrule
+    \end{tabular}
+  \end{table}
+
+  \small Times are total in seconds from on three replications each on
+  relatively recent server, using the \pkg{rbenchmark} package.
+\end{frame}
+
+\section{Summary / Outlook}
+\begin{frame}
+  \frametitle{Summary and Outlook}
+
+  \begin{itemize}
+  \item We have introduced the Google \textsl{Protocol Buffers} library as a
+    means to generating efficient data interfacing code: fast, auto-generated
+    and extensible.
+  \item We illustrated its use via our nascent \pkg{RProtoBuf} package.
+  \item \pkg{RProtoBuf} brings autogenerated accessors to \proglang{R},
+    albeit at a (currently) less-than-glamarous performance (mainly due to overheads within \proglang{R}).
+  \item The \pkg{Rcpp} package makes it easy to \textsl{manually} add Protocol
+    Buffers capabilities to our \proglang{R} analyses.
+  \item Goal: Use the new \textsl{Modules} feature in \pkg{Rcpp} to get at
+    (almost) auto-generated yet very efficient (\proglang{C++}-based) access
+    from \proglang{R}.
+  \item Second Goal: Add networking capabilities, maybe via \proglang{R}'s
+    built-in http server, or maybe by hijacking the connections interface.
+  \end{itemize}
+\end{frame}
+\end{document}
+
+%%% Local Variables:
+%%% mode: latex
+%%% TeX-master: t
+%%% End:
+


Property changes on: papers/user2010/slides.Rnw
___________________________________________________________________
Added: svn:executable
   + *



More information about the Rprotobuf-commits mailing list