[Rprotobuf-yada] reading messages from files

Romain François francoisromain at free.fr
Fri Nov 6 13:42:55 CET 2009


Hi,

Now reading a message from a file :

 > # example file that contains a "tutorial.AddressBook" message
 > book <- system.file( "examples", "AddressBookFile", package = 
"RProtoBuf" )
 > 

 > # read the message 

 > message <- read( tutorial.AddressBook, book ) 

 > 

 > # write its debug string 

 > writeLines( as.character( message ) ) 

person { 

   name: "Humpty Dumpty" 

   id: 1 

   email: "humpty at on.the.wall" 

   phone { 

     number: "123.456.789" 

     type: MOBILE 

   } 

   phone { 

     number: "111.222.333" 

     type: HOME 

   } 

} 

person { 

   name: "Someone WithoutEmail" 

   id: 2 

   phone { 

     number: "345.678.123" 

     type: WORK 

   } 

} 

person { 

   name: "Noemail Nophone" 

   id: 3 

} 

person { 

   name: "Many Phone" 

   id: 4 

   email: "very at important.com" 

   phone { 

     number: "111.111.111" 

     type: WORK 

   } 

   phone { 

     number: "222.222.222"
     type: MOBILE
   }
   phone {
     number: "333.333.333"
     type: MOBILE
   }
   phone {
     number: "444.444.444"
     type: HOME
   }
}

 >
 > # grab the name of each person
 > sapply( message$person, function(p) p$name )
[1] "Humpty Dumpty"        "Someone WithoutEmail" "Noemail Nophone"
[4] "Many Phone"


Romain

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/BcPw : celebrating R commit #50000
|- http://tr.im/ztCu : RGG #158:161: examples of package IDPmisc
`- http://tr.im/yw8E : New R package : sos



More information about the Rprotobuf-yada mailing list