SlideShare a Scribd company logo
Protocol Buffers RProtoBuf Summary / Outlook




          RProtoBuf: Protocol Buffers for R

               Romain François1                   Dirk Eddelbuettel2

                                       1R   Enthusiasts
                                       2 Debian   Project


                          useR! 2010
   National Institute of Standards and Technology (NIST)
               Gaithersburg, Maryland, USA




         Romain François and Dirk Eddelbuettel     RProtoBuf: Protocol Buffers for R @ useR! 2010
Protocol Buffers RProtoBuf Summary / Outlook

Outline




  1    Protocol Buffers

  2    RProtoBuf

  3    Summary / Outlook




               Romain François and Dirk Eddelbuettel   RProtoBuf: Protocol Buffers for R @ useR! 2010
Protocol Buffers RProtoBuf Summary / Outlook     Overview Example

Outline



  1    Protocol Buffers
         Overview
         Example

  2    RProtoBuf

  3    Summary / Outlook




               Romain François and Dirk Eddelbuettel   RProtoBuf: Protocol Buffers for R @ useR! 2010
Protocol Buffers RProtoBuf Summary / Outlook     Overview Example

Brief Description


       Google’s Protocol Buffers are a flexible, efficient,
       automated mechanism for serializing structured
       data—think XML, but smaller, faster, and simpler.
       Users define the data structures in a proto file, and then
       use special generated source code. Code is forwards- and
       backwards-compatible to proto changes.
       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— Java, C++, or Python.
       Or one can use third-party implementations for languages
       such as C#, Perl, Ruby, Haskell, and now R via the
       RProtoBuf package.


             Romain François and Dirk Eddelbuettel   RProtoBuf: Protocol Buffers for R @ useR! 2010
Protocol Buffers RProtoBuf Summary / Outlook     Overview Example

Features




                                                                   Protocol Buffers compare
                                                                   favourably against a
                                                                   number of competing
                                                                   data / messaging formats.


 Source: http://http://www.slideshare.net/kevinweil/

      protocol-buffers-and-hadoop-at-twitter




             Romain François and Dirk Eddelbuettel   RProtoBuf: Protocol Buffers for R @ useR! 2010
Protocol Buffers RProtoBuf Summary / Outlook     Overview Example

Example proto file from Tutorial

  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;
  }

             Romain François and Dirk Eddelbuettel   RProtoBuf: Protocol Buffers for R @ useR! 2010
Protocol Buffers RProtoBuf Summary / Outlook     Overview Example

Example C++ usage

  #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;
       }


            Romain François and Dirk Eddelbuettel   RProtoBuf: Protocol Buffers for R @ useR! 2010
Protocol Buffers RProtoBuf Summary / Outlook     Overview Example

Example C++ usage (cont.)

          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;
          }
      }
  }
               Romain François and Dirk Eddelbuettel   RProtoBuf: Protocol Buffers for R @ useR! 2010
Protocol Buffers RProtoBuf Summary / Outlook     Overview Examples Writer R Readers

Outline


  1    Protocol Buffers

  2    RProtoBuf
         Overview
         Examples
               Adressbook
               (Stylized) High-Frequency Financial Data
           Writer
           R Readers

  3    Summary / Outlook




               Romain François and Dirk Eddelbuettel   RProtoBuf: Protocol Buffers for R @ useR! 2010
Protocol Buffers RProtoBuf Summary / Outlook     Overview Examples Writer R Readers

Brief Description


       The RProtoBuf package implements R bindings to the
       C++ protobuf library from Google.
       RProtoBuf uses features of the protocol buffer library to
       support creation, manipulation, parsing and serialization of
       protocol buffers messages.
       Taking advantage of facilities in the Rcpp package,
       RProtoBuf uses S4 classes and external pointers to
       expose objects that look and feel like standard R lists, yet
       are managed by the underlying C++ library.
       These objects also conform to the language-agnostic
       definition of the message type allowing access to their
       content from other supported languages.


             Romain François and Dirk Eddelbuettel   RProtoBuf: Protocol Buffers for R @ useR! 2010
Protocol Buffers RProtoBuf Summary / Outlook     Overview Examples Writer R Readers

Addressbook example from R
See demo(addressbook)



   >    # load the package
   >    require( RProtoBuf )
   >    # read the proto file
   >    readProtoFiles( files="addressbook.proto" )
   >    # create a prototype with a call to new
   >    # on the descriptor for the Person type,
   >    romain <- new( tutorial.Person )
   >    # then update the message
   >    romain <- update( romain ,
   +       email = "romain@r-enthusiasts.com",
   +       id = 1, name = "Romain Francois",
   +       phone = new(tutorial.Person.PhoneNumber,
   +         number = "+33(0)...", type = "MOBILE"))



                Romain François and Dirk Eddelbuettel   RProtoBuf: Protocol Buffers for R @ useR! 2010
Protocol Buffers RProtoBuf Summary / Outlook     Overview Examples Writer R Readers

Addressbook example from R (cont)



  > # directly supply parameters to the ctor
  > dirk <- new( tutorial.Person,
  +    email = "edd@debian.org",
  +          id = 2, name = "Dirk Eddelbuettel" )
  > # update the phone repeated field with list
  > dirk$phone <- list(
  +        new( tutorial.Person.PhoneNumber,
  +             number = "+01...", type = "MOBILE" ),
  +        new( tutorial.Person.PhoneNumber ,
  +             number = "+01...", type = "HOME" ) )




               Romain François and Dirk Eddelbuettel   RProtoBuf: Protocol Buffers for R @ useR! 2010
Protocol Buffers RProtoBuf Summary / Outlook     Overview Examples Writer R Readers

Addressbook example from R (cont)



  > # build the address book
  > book <- new( tutorial.AddressBook,
  +                              person = list( romain, dirk ) )
  >    # debug content - this is not wire content
  >    writeLines( as.character( book ) )
  >    # the serialized message,
  >    # see also the io demo
  >    serialize( book, NULL )




               Romain François and Dirk Eddelbuettel   RProtoBuf: Protocol Buffers for R @ useR! 2010
Protocol Buffers RProtoBuf Summary / Outlook     Overview Examples Writer R Readers

Example proto file for Financial Data

   // 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;
   }
  See inst/examples/HighFrequencyFinance/ in the RProtoBuf package.


                Romain François and Dirk Eddelbuettel   RProtoBuf: Protocol Buffers for R @ useR! 2010
Protocol Buffers RProtoBuf Summary / Outlook     Overview Examples Writer R Readers

Example C++ data creator

  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;
  }


  See inst/examples/HighFrequencyFinance/protoCreate.cpp


              Romain François and Dirk Eddelbuettel   RProtoBuf: Protocol Buffers for R @ useR! 2010
Protocol Buffers RProtoBuf Summary / Outlook     Overview Examples Writer R Readers

Extensibility
  We could add this to the proto file:

    enum exchType {
      NYSE = 0; NASDAQ = 1; ARCS = 2; BATS = 3;
    }
    optional exchType exchange = 5 [default = NYSE];


        If you want your new buffers to be backwards-compatible,
        and your old buffers to be forward-compatible [...]:
              you must not change the tag [...] of any existing fields.
              you must not add or delete any required fields.
              you may delete optional or repeated fields.
              you may add new optional or repeated fields but you
              must use fresh tag numbers [...]

  See http://code.google.com/apis/protocolbuffers/
  docs/cpptutorial.html
             Romain François and Dirk Eddelbuettel   RProtoBuf: Protocol Buffers for R @ useR! 2010
Protocol Buffers RProtoBuf Summary / Outlook     Overview Examples Writer R Readers

Example R reader: Simple


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

  See inst/examples/HighFrequencyFinance/loadInR.r




              Romain François and Dirk Eddelbuettel   RProtoBuf: Protocol Buffers for R @ useR! 2010
Protocol Buffers RProtoBuf Summary / Outlook     Overview Examples Writer R Readers

Example R reader: Smarter

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

  See inst/examples/HighFrequencyFinance/loadInR.r




              Romain François and Dirk Eddelbuettel   RProtoBuf: Protocol Buffers for R @ useR! 2010
Protocol Buffers RProtoBuf Summary / Outlook     Overview Examples Writer R Readers

Example R reader: Manual via Rcpp


  > compiled <- function(verbose=FALSE,
  +                      file="trades.pb") {
  +
  +     stopifnot(file.exists(file))
  +
  +     df <- .Call("pbload", file);
  +
  +     if (verbose) print(summary(df))
  +
  +     invisible(df)
  + }

  See inst/examples/HighFrequencyFinance/loadInR.r




              Romain François and Dirk Eddelbuettel   RProtoBuf: Protocol Buffers for R @ useR! 2010
Protocol Buffers RProtoBuf Summary / Outlook     Overview Examples Writer R Readers

Example R reader: C++ support

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

  See inst/examples/HighFrequencyFinance/protoModule.cpp



              Romain François and Dirk Eddelbuettel   RProtoBuf: Protocol Buffers for R @ useR! 2010
Protocol Buffers RProtoBuf Summary / Outlook     Overview Examples Writer R Readers

Timing comparison


  Running the script loadInR.r from the aforementioned
  examples directory in the RProtoBuf package:

                      Version             Elapsed Time             Relative
                      Compiled                       0.006         1.0000
                      betterUse                      0.138        23.0000
                      basicUse                       4.606       767.6667

  Times are total in seconds from on three replications each on
  relatively recent server, using the rbenchmark package.




             Romain François and Dirk Eddelbuettel   RProtoBuf: Protocol Buffers for R @ useR! 2010
Protocol Buffers RProtoBuf Summary / Outlook     Summary Outlook

Outline



  1    Protocol Buffers

  2    RProtoBuf

  3    Summary / Outlook
         Summary
         Outlook




               Romain François and Dirk Eddelbuettel   RProtoBuf: Protocol Buffers for R @ useR! 2010
Protocol Buffers RProtoBuf Summary / Outlook     Summary Outlook

Summary



      We have introduced the Google Protocol Buffers library as
      a means to generating efficient data interfacing code: fast,
      auto-generated and extensible.
      We illustrated its use via our nascent RProtoBuf package.
      RProtoBuf brings autogenerated accessors to R—which
      may however not be the fastest access.
      The Rcpp package makes it easy to manually add
      Protocol Buffers capabilities to our R analyses.




            Romain François and Dirk Eddelbuettel   RProtoBuf: Protocol Buffers for R @ useR! 2010
Protocol Buffers RProtoBuf Summary / Outlook     Summary Outlook

Outlook




      Goal: Use the new Modules feature in Rcpp to get at
      (almost) auto-generated yet very efficient (C++-based)
      access from R.
      Second Goal: Add networking capabilities, maybe via R’s
      built-in http server.




            Romain François and Dirk Eddelbuettel   RProtoBuf: Protocol Buffers for R @ useR! 2010

More Related Content

What's hot

Python introduction
Python introductionPython introduction
Python introduction
Learnbay Datascience
 
C programming session 11
C programming session 11C programming session 11
C programming session 11Vivek Singh
 
Chapter Three(1)
Chapter Three(1)Chapter Three(1)
Chapter Three(1)bolovv
 
Fundamentals of programming and problem solving
Fundamentals of programming and problem solvingFundamentals of programming and problem solving
Fundamentals of programming and problem solvingJustine Dela Serna
 
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGESOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
IJCI JOURNAL
 
The C++ Programming Language
The C++ Programming LanguageThe C++ Programming Language
The C++ Programming Language
Prof Ansari
 
Rpg Pointers And User Space
Rpg Pointers And User SpaceRpg Pointers And User Space
Rpg Pointers And User Space
ramanjosan
 
Standardising on C++
Standardising on C++Standardising on C++
Standardising on C++
Kevlin Henney
 
The future of DSLs - functions and formal methods
The future of DSLs - functions and formal methodsThe future of DSLs - functions and formal methods
The future of DSLs - functions and formal methods
Markus Voelter
 
Learning R via Python…or the other way around
Learning R via Python…or the other way aroundLearning R via Python…or the other way around
Learning R via Python…or the other way aroundSid Xing
 
X86 assembly nasm syntax
X86 assembly nasm syntaxX86 assembly nasm syntax
X86 assembly nasm syntax
Francesco DiFusco
 
C language
C languageC language
C language
spatidar0
 
Introduction of c language
Introduction of c languageIntroduction of c language
Introduction of c language
farishah
 
EST 102 Programming in C-MODULE 5
 EST 102 Programming in C-MODULE 5 EST 102 Programming in C-MODULE 5
EST 102 Programming in C-MODULE 5
NIMMYRAJU
 
Generative programming (mostly parser generation)
Generative programming (mostly parser generation)Generative programming (mostly parser generation)
Generative programming (mostly parser generation)Ralf Laemmel
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
Yi-Fan Chu
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
amiable_indian
 
Compiler Design File
Compiler Design FileCompiler Design File
Compiler Design File
Archita Misra
 
Python Presentation
Python PresentationPython Presentation
Python Presentation
Narendra Sisodiya
 

What's hot (20)

Python introduction
Python introductionPython introduction
Python introduction
 
C programming session 11
C programming session 11C programming session 11
C programming session 11
 
Chapter Three(1)
Chapter Three(1)Chapter Three(1)
Chapter Three(1)
 
Fundamentals of programming and problem solving
Fundamentals of programming and problem solvingFundamentals of programming and problem solving
Fundamentals of programming and problem solving
 
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGESOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
 
The C++ Programming Language
The C++ Programming LanguageThe C++ Programming Language
The C++ Programming Language
 
Rpg Pointers And User Space
Rpg Pointers And User SpaceRpg Pointers And User Space
Rpg Pointers And User Space
 
20 -miscellaneous
20  -miscellaneous20  -miscellaneous
20 -miscellaneous
 
Standardising on C++
Standardising on C++Standardising on C++
Standardising on C++
 
The future of DSLs - functions and formal methods
The future of DSLs - functions and formal methodsThe future of DSLs - functions and formal methods
The future of DSLs - functions and formal methods
 
Learning R via Python…or the other way around
Learning R via Python…or the other way aroundLearning R via Python…or the other way around
Learning R via Python…or the other way around
 
X86 assembly nasm syntax
X86 assembly nasm syntaxX86 assembly nasm syntax
X86 assembly nasm syntax
 
C language
C languageC language
C language
 
Introduction of c language
Introduction of c languageIntroduction of c language
Introduction of c language
 
EST 102 Programming in C-MODULE 5
 EST 102 Programming in C-MODULE 5 EST 102 Programming in C-MODULE 5
EST 102 Programming in C-MODULE 5
 
Generative programming (mostly parser generation)
Generative programming (mostly parser generation)Generative programming (mostly parser generation)
Generative programming (mostly parser generation)
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
 
Compiler Design File
Compiler Design FileCompiler Design File
Compiler Design File
 
Python Presentation
Python PresentationPython Presentation
Python Presentation
 

Similar to RProtoBuf: protocol buffers for R

Docopt, beautiful command-line options for R, user2014
Docopt, beautiful command-line options for R,  user2014Docopt, beautiful command-line options for R,  user2014
Docopt, beautiful command-line options for R, user2014
Edwin de Jonge
 
Apa style-1 (1)
Apa style-1 (1)Apa style-1 (1)
Apa style-1 (1)
Nicolas Jia Quan
 
A Research Study of Data Collection and Analysis of Semantics of Programming ...
A Research Study of Data Collection and Analysis of Semantics of Programming ...A Research Study of Data Collection and Analysis of Semantics of Programming ...
A Research Study of Data Collection and Analysis of Semantics of Programming ...
IRJET Journal
 
Introduction of Python
Introduction of PythonIntroduction of Python
Introduction of Python
ZENUS INFOTECH INDIA PVT. LTD.
 
Socket programming-in-python
Socket programming-in-pythonSocket programming-in-python
Socket programming-in-python
Yuvaraja Ravi
 
Integrating R with C++: Rcpp, RInside and RProtoBuf
Integrating R with C++: Rcpp, RInside and RProtoBufIntegrating R with C++: Rcpp, RInside and RProtoBuf
Integrating R with C++: Rcpp, RInside and RProtoBuf
Romain Francois
 
Building scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thriftBuilding scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thrift
Talentica Software
 
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdfpython-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
KosmikTech1
 
Microservices for building an IDE – The innards of JetBrains Rider - TechDays...
Microservices for building an IDE – The innards of JetBrains Rider - TechDays...Microservices for building an IDE – The innards of JetBrains Rider - TechDays...
Microservices for building an IDE – The innards of JetBrains Rider - TechDays...
Maarten Balliauw
 
F# Tutorial @ QCon
F# Tutorial @ QConF# Tutorial @ QCon
F# Tutorial @ QCon
Tomas Petricek
 
python ppt | Python Course In Ghaziabad | Scode Network Institute
python ppt | Python Course In Ghaziabad | Scode Network Institutepython ppt | Python Course In Ghaziabad | Scode Network Institute
python ppt | Python Course In Ghaziabad | Scode Network Institute
Scode Network Institute
 
Report on c and c++
Report on c and c++Report on c and c++
Report on c and c++
oggyrao
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
Kengatharaiyer Sarveswaran
 
Introduction to C Unit 1
Introduction to C Unit 1Introduction to C Unit 1
Introduction to C Unit 1
SURBHI SAROHA
 
Will iPython replace bash?
Will iPython replace bash?Will iPython replace bash?
Will iPython replace bash?
Roberto Polli
 
Will iPython replace Bash?
Will iPython replace Bash?Will iPython replace Bash?
Will iPython replace Bash?
Babel
 
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTH
Bhavsingh Maloth
 
Combinators, DSLs, HTML and F#
Combinators, DSLs, HTML and F#Combinators, DSLs, HTML and F#
Combinators, DSLs, HTML and F#Robert Pickering
 
Building scalable and language-independent Java services using Apache Thrift ...
Building scalable and language-independent Java services using Apache Thrift ...Building scalable and language-independent Java services using Apache Thrift ...
Building scalable and language-independent Java services using Apache Thrift ...
IndicThreads
 

Similar to RProtoBuf: protocol buffers for R (20)

Docopt, beautiful command-line options for R, user2014
Docopt, beautiful command-line options for R,  user2014Docopt, beautiful command-line options for R,  user2014
Docopt, beautiful command-line options for R, user2014
 
Apa style-1 (1)
Apa style-1 (1)Apa style-1 (1)
Apa style-1 (1)
 
A Research Study of Data Collection and Analysis of Semantics of Programming ...
A Research Study of Data Collection and Analysis of Semantics of Programming ...A Research Study of Data Collection and Analysis of Semantics of Programming ...
A Research Study of Data Collection and Analysis of Semantics of Programming ...
 
Introduction of Python
Introduction of PythonIntroduction of Python
Introduction of Python
 
Socket programming-in-python
Socket programming-in-pythonSocket programming-in-python
Socket programming-in-python
 
Integrating R with C++: Rcpp, RInside and RProtoBuf
Integrating R with C++: Rcpp, RInside and RProtoBufIntegrating R with C++: Rcpp, RInside and RProtoBuf
Integrating R with C++: Rcpp, RInside and RProtoBuf
 
Building scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thriftBuilding scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thrift
 
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdfpython-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
 
Microservices for building an IDE – The innards of JetBrains Rider - TechDays...
Microservices for building an IDE – The innards of JetBrains Rider - TechDays...Microservices for building an IDE – The innards of JetBrains Rider - TechDays...
Microservices for building an IDE – The innards of JetBrains Rider - TechDays...
 
python and perl
python and perlpython and perl
python and perl
 
F# Tutorial @ QCon
F# Tutorial @ QConF# Tutorial @ QCon
F# Tutorial @ QCon
 
python ppt | Python Course In Ghaziabad | Scode Network Institute
python ppt | Python Course In Ghaziabad | Scode Network Institutepython ppt | Python Course In Ghaziabad | Scode Network Institute
python ppt | Python Course In Ghaziabad | Scode Network Institute
 
Report on c and c++
Report on c and c++Report on c and c++
Report on c and c++
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Introduction to C Unit 1
Introduction to C Unit 1Introduction to C Unit 1
Introduction to C Unit 1
 
Will iPython replace bash?
Will iPython replace bash?Will iPython replace bash?
Will iPython replace bash?
 
Will iPython replace Bash?
Will iPython replace Bash?Will iPython replace Bash?
Will iPython replace Bash?
 
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTH
 
Combinators, DSLs, HTML and F#
Combinators, DSLs, HTML and F#Combinators, DSLs, HTML and F#
Combinators, DSLs, HTML and F#
 
Building scalable and language-independent Java services using Apache Thrift ...
Building scalable and language-independent Java services using Apache Thrift ...Building scalable and language-independent Java services using Apache Thrift ...
Building scalable and language-independent Java services using Apache Thrift ...
 

More from Romain Francois

R/C++
R/C++R/C++
dplyr and torrents from cpasbien
dplyr and torrents from cpasbiendplyr and torrents from cpasbien
dplyr and torrents from cpasbien
Romain Francois
 
dplyr use case
dplyr use casedplyr use case
dplyr use case
Romain Francois
 
dplyr
dplyrdplyr
SevillaR meetup: dplyr and magrittr
SevillaR meetup: dplyr and magrittrSevillaR meetup: dplyr and magrittr
SevillaR meetup: dplyr and magrittr
Romain Francois
 
dplyr
dplyrdplyr
Data manipulation with dplyr
Data manipulation with dplyrData manipulation with dplyr
Data manipulation with dplyr
Romain Francois
 
R/C++ talk at earl 2014
R/C++ talk at earl 2014R/C++ talk at earl 2014
R/C++ talk at earl 2014
Romain Francois
 
Rcpp11 genentech
Rcpp11 genentechRcpp11 genentech
Rcpp11 genentech
Romain Francois
 
Rcpp11 useR2014
Rcpp11 useR2014Rcpp11 useR2014
Rcpp11 useR2014
Romain Francois
 
Rcpp11
Rcpp11Rcpp11
R and C++
R and C++R and C++
R and C++
Romain Francois
 
R and cpp
R and cppR and cpp
R and cpp
Romain Francois
 
Object Oriented Design(s) in R
Object Oriented Design(s) in RObject Oriented Design(s) in R
Object Oriented Design(s) in R
Romain Francois
 
Rcpp: Seemless R and C++
Rcpp: Seemless R and C++Rcpp: Seemless R and C++
Rcpp: Seemless R and C++Romain Francois
 
Rcpp: Seemless R and C++
Rcpp: Seemless R and C++Rcpp: Seemless R and C++
Rcpp: Seemless R and C++Romain Francois
 

More from Romain Francois (20)

R/C++
R/C++R/C++
R/C++
 
dplyr and torrents from cpasbien
dplyr and torrents from cpasbiendplyr and torrents from cpasbien
dplyr and torrents from cpasbien
 
dplyr use case
dplyr use casedplyr use case
dplyr use case
 
dplyr
dplyrdplyr
dplyr
 
user2015 keynote talk
user2015 keynote talkuser2015 keynote talk
user2015 keynote talk
 
SevillaR meetup: dplyr and magrittr
SevillaR meetup: dplyr and magrittrSevillaR meetup: dplyr and magrittr
SevillaR meetup: dplyr and magrittr
 
dplyr
dplyrdplyr
dplyr
 
Data manipulation with dplyr
Data manipulation with dplyrData manipulation with dplyr
Data manipulation with dplyr
 
R/C++ talk at earl 2014
R/C++ talk at earl 2014R/C++ talk at earl 2014
R/C++ talk at earl 2014
 
Rcpp11 genentech
Rcpp11 genentechRcpp11 genentech
Rcpp11 genentech
 
Rcpp11 useR2014
Rcpp11 useR2014Rcpp11 useR2014
Rcpp11 useR2014
 
Rcpp11
Rcpp11Rcpp11
Rcpp11
 
R and C++
R and C++R and C++
R and C++
 
R and cpp
R and cppR and cpp
R and cpp
 
Rcpp attributes
Rcpp attributesRcpp attributes
Rcpp attributes
 
Rcpp is-ready
Rcpp is-readyRcpp is-ready
Rcpp is-ready
 
Rcpp
RcppRcpp
Rcpp
 
Object Oriented Design(s) in R
Object Oriented Design(s) in RObject Oriented Design(s) in R
Object Oriented Design(s) in R
 
Rcpp: Seemless R and C++
Rcpp: Seemless R and C++Rcpp: Seemless R and C++
Rcpp: Seemless R and C++
 
Rcpp: Seemless R and C++
Rcpp: Seemless R and C++Rcpp: Seemless R and C++
Rcpp: Seemless R and C++
 

Recently uploaded

GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 

Recently uploaded (20)

GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 

RProtoBuf: protocol buffers for R

  • 1. Protocol Buffers RProtoBuf Summary / Outlook RProtoBuf: Protocol Buffers for R Romain François1 Dirk Eddelbuettel2 1R Enthusiasts 2 Debian Project useR! 2010 National Institute of Standards and Technology (NIST) Gaithersburg, Maryland, USA Romain François and Dirk Eddelbuettel RProtoBuf: Protocol Buffers for R @ useR! 2010
  • 2. Protocol Buffers RProtoBuf Summary / Outlook Outline 1 Protocol Buffers 2 RProtoBuf 3 Summary / Outlook Romain François and Dirk Eddelbuettel RProtoBuf: Protocol Buffers for R @ useR! 2010
  • 3. Protocol Buffers RProtoBuf Summary / Outlook Overview Example Outline 1 Protocol Buffers Overview Example 2 RProtoBuf 3 Summary / Outlook Romain François and Dirk Eddelbuettel RProtoBuf: Protocol Buffers for R @ useR! 2010
  • 4. Protocol Buffers RProtoBuf Summary / Outlook Overview Example Brief Description Google’s Protocol Buffers are a flexible, efficient, automated mechanism for serializing structured data—think XML, but smaller, faster, and simpler. Users define the data structures in a proto file, and then use special generated source code. Code is forwards- and backwards-compatible to proto changes. 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— Java, C++, or Python. Or one can use third-party implementations for languages such as C#, Perl, Ruby, Haskell, and now R via the RProtoBuf package. Romain François and Dirk Eddelbuettel RProtoBuf: Protocol Buffers for R @ useR! 2010
  • 5. Protocol Buffers RProtoBuf Summary / Outlook Overview Example Features Protocol Buffers compare favourably against a number of competing data / messaging formats. Source: http://http://www.slideshare.net/kevinweil/ protocol-buffers-and-hadoop-at-twitter Romain François and Dirk Eddelbuettel RProtoBuf: Protocol Buffers for R @ useR! 2010
  • 6. Protocol Buffers RProtoBuf Summary / Outlook Overview Example Example proto file from Tutorial 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; } Romain François and Dirk Eddelbuettel RProtoBuf: Protocol Buffers for R @ useR! 2010
  • 7. Protocol Buffers RProtoBuf Summary / Outlook Overview Example Example C++ usage #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; } Romain François and Dirk Eddelbuettel RProtoBuf: Protocol Buffers for R @ useR! 2010
  • 8. Protocol Buffers RProtoBuf Summary / Outlook Overview Example Example C++ usage (cont.) 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; } } } Romain François and Dirk Eddelbuettel RProtoBuf: Protocol Buffers for R @ useR! 2010
  • 9. Protocol Buffers RProtoBuf Summary / Outlook Overview Examples Writer R Readers Outline 1 Protocol Buffers 2 RProtoBuf Overview Examples Adressbook (Stylized) High-Frequency Financial Data Writer R Readers 3 Summary / Outlook Romain François and Dirk Eddelbuettel RProtoBuf: Protocol Buffers for R @ useR! 2010
  • 10. Protocol Buffers RProtoBuf Summary / Outlook Overview Examples Writer R Readers Brief Description The RProtoBuf package implements R bindings to the C++ protobuf library from Google. RProtoBuf uses features of the protocol buffer library to support creation, manipulation, parsing and serialization of protocol buffers messages. Taking advantage of facilities in the Rcpp package, RProtoBuf uses S4 classes and external pointers to expose objects that look and feel like standard R lists, yet are managed by the underlying C++ library. These objects also conform to the language-agnostic definition of the message type allowing access to their content from other supported languages. Romain François and Dirk Eddelbuettel RProtoBuf: Protocol Buffers for R @ useR! 2010
  • 11. Protocol Buffers RProtoBuf Summary / Outlook Overview Examples Writer R Readers Addressbook example from R See demo(addressbook) > # load the package > require( RProtoBuf ) > # read the proto file > readProtoFiles( files="addressbook.proto" ) > # create a prototype with a call to new > # on the descriptor for the Person type, > romain <- new( tutorial.Person ) > # then update the message > romain <- update( romain , + email = "romain@r-enthusiasts.com", + id = 1, name = "Romain Francois", + phone = new(tutorial.Person.PhoneNumber, + number = "+33(0)...", type = "MOBILE")) Romain François and Dirk Eddelbuettel RProtoBuf: Protocol Buffers for R @ useR! 2010
  • 12. Protocol Buffers RProtoBuf Summary / Outlook Overview Examples Writer R Readers Addressbook example from R (cont) > # directly supply parameters to the ctor > dirk <- new( tutorial.Person, + email = "edd@debian.org", + id = 2, name = "Dirk Eddelbuettel" ) > # update the phone repeated field with list > dirk$phone <- list( + new( tutorial.Person.PhoneNumber, + number = "+01...", type = "MOBILE" ), + new( tutorial.Person.PhoneNumber , + number = "+01...", type = "HOME" ) ) Romain François and Dirk Eddelbuettel RProtoBuf: Protocol Buffers for R @ useR! 2010
  • 13. Protocol Buffers RProtoBuf Summary / Outlook Overview Examples Writer R Readers Addressbook example from R (cont) > # build the address book > book <- new( tutorial.AddressBook, + person = list( romain, dirk ) ) > # debug content - this is not wire content > writeLines( as.character( book ) ) > # the serialized message, > # see also the io demo > serialize( book, NULL ) Romain François and Dirk Eddelbuettel RProtoBuf: Protocol Buffers for R @ useR! 2010
  • 14. Protocol Buffers RProtoBuf Summary / Outlook Overview Examples Writer R Readers Example proto file for Financial Data // 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; } See inst/examples/HighFrequencyFinance/ in the RProtoBuf package. Romain François and Dirk Eddelbuettel RProtoBuf: Protocol Buffers for R @ useR! 2010
  • 15. Protocol Buffers RProtoBuf Summary / Outlook Overview Examples Writer R Readers Example C++ data creator 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; } See inst/examples/HighFrequencyFinance/protoCreate.cpp Romain François and Dirk Eddelbuettel RProtoBuf: Protocol Buffers for R @ useR! 2010
  • 16. Protocol Buffers RProtoBuf Summary / Outlook Overview Examples Writer R Readers Extensibility We could add this to the proto file: enum exchType { NYSE = 0; NASDAQ = 1; ARCS = 2; BATS = 3; } optional exchType exchange = 5 [default = NYSE]; If you want your new buffers to be backwards-compatible, and your old buffers to be forward-compatible [...]: you must not change the tag [...] of any existing fields. you must not add or delete any required fields. you may delete optional or repeated fields. you may add new optional or repeated fields but you must use fresh tag numbers [...] See http://code.google.com/apis/protocolbuffers/ docs/cpptutorial.html Romain François and Dirk Eddelbuettel RProtoBuf: Protocol Buffers for R @ useR! 2010
  • 17. Protocol Buffers RProtoBuf Summary / Outlook Overview Examples Writer R Readers Example R reader: Simple > 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) + } See inst/examples/HighFrequencyFinance/loadInR.r Romain François and Dirk Eddelbuettel RProtoBuf: Protocol Buffers for R @ useR! 2010
  • 18. Protocol Buffers RProtoBuf Summary / Outlook Overview Examples Writer R Readers Example R reader: Smarter > 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) + } See inst/examples/HighFrequencyFinance/loadInR.r Romain François and Dirk Eddelbuettel RProtoBuf: Protocol Buffers for R @ useR! 2010
  • 19. Protocol Buffers RProtoBuf Summary / Outlook Overview Examples Writer R Readers Example R reader: Manual via Rcpp > compiled <- function(verbose=FALSE, + file="trades.pb") { + + stopifnot(file.exists(file)) + + df <- .Call("pbload", file); + + if (verbose) print(summary(df)) + + invisible(df) + } See inst/examples/HighFrequencyFinance/loadInR.r Romain François and Dirk Eddelbuettel RProtoBuf: Protocol Buffers for R @ useR! 2010
  • 20. Protocol Buffers RProtoBuf Summary / Outlook Overview Examples Writer R Readers Example R reader: C++ support 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); } See inst/examples/HighFrequencyFinance/protoModule.cpp Romain François and Dirk Eddelbuettel RProtoBuf: Protocol Buffers for R @ useR! 2010
  • 21. Protocol Buffers RProtoBuf Summary / Outlook Overview Examples Writer R Readers Timing comparison Running the script loadInR.r from the aforementioned examples directory in the RProtoBuf package: Version Elapsed Time Relative Compiled 0.006 1.0000 betterUse 0.138 23.0000 basicUse 4.606 767.6667 Times are total in seconds from on three replications each on relatively recent server, using the rbenchmark package. Romain François and Dirk Eddelbuettel RProtoBuf: Protocol Buffers for R @ useR! 2010
  • 22. Protocol Buffers RProtoBuf Summary / Outlook Summary Outlook Outline 1 Protocol Buffers 2 RProtoBuf 3 Summary / Outlook Summary Outlook Romain François and Dirk Eddelbuettel RProtoBuf: Protocol Buffers for R @ useR! 2010
  • 23. Protocol Buffers RProtoBuf Summary / Outlook Summary Outlook Summary We have introduced the Google Protocol Buffers library as a means to generating efficient data interfacing code: fast, auto-generated and extensible. We illustrated its use via our nascent RProtoBuf package. RProtoBuf brings autogenerated accessors to R—which may however not be the fastest access. The Rcpp package makes it easy to manually add Protocol Buffers capabilities to our R analyses. Romain François and Dirk Eddelbuettel RProtoBuf: Protocol Buffers for R @ useR! 2010
  • 24. Protocol Buffers RProtoBuf Summary / Outlook Summary Outlook Outlook Goal: Use the new Modules feature in Rcpp to get at (almost) auto-generated yet very efficient (C++-based) access from R. Second Goal: Add networking capabilities, maybe via R’s built-in http server. Romain François and Dirk Eddelbuettel RProtoBuf: Protocol Buffers for R @ useR! 2010