Romain Francois, Professional R EnthusiastIndependant statistical/R consultant2013-03-24T15:53:22+01:00Romain Francoisurn:md5:2cdb21a695f56bfe2b31ee2133c51b42DotclearMovingurn:md5:06fe049220fc5f13c7b5329ce661fee12013-03-24T16:52:00+01:00romain francoisR <img src="http://romainfrancois.blog.free.fr/public/posts/moving/.Moving_Boxes___Packing_Material_m.jpg" alt="Moving_Boxes___Packing_Material.jpg" style="margin: 0 auto; display: block;" title="Moving_Boxes___Packing_Material.jpg, mar. 2013" />
<p>This blog is moving to <a href="http://blog.r-enthusiasts.com">blog.r-enthusiasts.com</a>. The new one is powered by wordpress and gets a subdomain of <code>r-enthusiasts.com</code>. </p>
<p>See you there</p>Improving the graph galleryurn:md5:4754800f1f036c5cfae284f408bffd892013-02-18T08:37:00+01:00romain francoisgraphgalleryR <script type="text/javascript"><!--
google_ad_client = "ca-pub-0193080271541659";
/* blog */
google_ad_slot = "4394100836";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<br />
<br />
<p>I'm trying to make improvements to the <a href="http://gallery.r-enthusiasts.com">R Graph Gallery</a>, I'm looking for suggestions from users of the website.</p>
<p>I've started a <a href="http://www.facebook.com/questions/425893104160507/">question</a> on the website's <a href="http://www.facebook.com/pages/R-Graph-Gallery/169231589826661">facebook page</a>. Please take a few seconds to vote to existing improvements possibilities and perhaps offer some of your own ideas. </p>
<br />
<a href="http://gallery.r-enthusiasts.com/"><img src="http://romainfrancois.blog.free.fr/public/graphgallery/.graph-gallery_m.jpg" alt="graph-gallery.png" style="margin: 0 auto; display: block;" title="graph-gallery.png, fév. 2013" /></a>bibtex 0.3-5urn:md5:e8986a3734b6d188873d3288f7c4cdcf2013-02-04T11:59:00+01:00romain francoisbibtex <br/><br/>
<img src="http://romainfrancois.blog.free.fr/public/packages/bibtex/bibtex.png" alt="bibtex.png" style="margin: 0 auto; display: block;" title="bibtex.png, fév. 2013" />
<p>The version 0.3-5 of the <strong>bibtex</strong> package is on CRAN. This fixes a corner case issue about empty bib files thanks to Kurt Hornik. </p>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0193080271541659";
/* blog */
google_ad_slot = "4394100836";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<br />
<br />OOP with Rcpp modulesurn:md5:c42719b110c2ef56c53fa87965cce5412012-11-05T16:24:00+01:00romain francoisRcppcplusplusOOPRRcpp <script type="text/javascript"><!--
google_ad_client = "ca-pub-0193080271541659";
/* blog */
google_ad_slot = "4394100836";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<br />
<br />
<p>The purpose of <a href="http://dirk.eddelbuettel.com/code/rcpp.html">Rcpp</a> modules has always been to make it easy to expose C++ functions and classes to R. Up to now, Rcpp modules did not have a way to declare inheritance between C++ classes. This is now fixed in the development version, and the next version of Rcpp will have a simple mechanism to declare inheritance. </p>
<p>Consider this simple example, we have a base class <strong>Shape</strong> with two virtual methods (<strong>area</strong> and <strong>contains</strong>) and two classes <strong>Circle</strong> and <strong>Rectangle</strong>) each deriving from <strong>Shape</strong> and representing a specific shape. </p>
<p>The classes might look like this: </p>
<iframe src="http://romainfrancois.blog.free.fr/public/posts/shapes/classes.html" width=500 height=900 frameborder=0></iframe>
<p>And we can expose these classes to R using the following module declarative code: </p>
<iframe src="http://romainfrancois.blog.free.fr/public/posts/shapes/module.html" width=500 height=400 frameborder=0></iframe>
<p>It is worth noticing that: </p>
<ul>
<li>The <strong>area</strong> and <strong>contains</strong> methods are exposed as part of the base <strong>Shape</strong> class</li>
<li>Classes <strong>Rectangle</strong> and <strong>Circle</strong> simply declare that they derive from <strong>Shape</strong> using the <strong>derives</strong> notation. </li>
</ul>
<p>R code that uses these classes looks like this: </p>
<iframe src="http://romainfrancois.blog.free.fr/public/posts/shapes/play.html" width=500 height=200 frameborder=0></iframe>
<img src="http://romainfrancois.blog.free.fr/public/posts/shapes/.shapes_m.jpg" alt="shapes.jpg" style="margin: 0 auto; display: block;" title="shapes.jpg, nov. 2012" />Rcpp modules more flexibleurn:md5:3d2b60562b22c523c4aee4e6c641087b2012-10-25T10:25:00+02:00romain francoisRcppcplusplusRRcpp <script type="text/javascript"><!--
google_ad_client = "ca-pub-0193080271541659";
/* blog */
google_ad_slot = "4394100836";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<br />
<p>
<a href="http://dirk.eddelbuettel.com/code/rcpp.html">Rcpp</a> modules just got more flexible (as of revision 3838 of Rcpp, to become 0.9.16 in the future).
</p>
<p>
modules have allowed exposing C++ classes for some time now, but developpers had to declare custom wrap and as specializations if they wanted their classes to be used as return type or argument type of a C++ function or method. This led to writing boilerplate code. The newest devel version allows for syntax like this:
</p>
<iframe src="http://romainfrancois.blog.free.fr/public/packages/Rcpp/Mod.cpp.html" width=500 height=650 frameborder="0" scrolling=none>Mod.cpp.html</iframe>
<p>The only thing the developper has to do is to declare the class using the macro RCPP_EXPOSED_CLASS. This will declare the appropriate class traits that Rcpp is using for internal implementations of as and wrap</p>
<p>One the example we can see three examples of the new functionality:</p>
<ul>
<li><strong>make_foo</strong> : this returns a Foo</li>
<li><strong>cloner</strong>: this returns a Foo*</li>
<li><strong>bla</strong>: uses a const Foo& as argument</li>
</ul>
<br/>
<br/>Crawling facebook with Rurn:md5:4be4f03f9d92b08ae3cbf595eb3844342012-01-15T18:37:00+01:00romain francoisfacebookR <script type="text/javascript"><!--
google_ad_client = "ca-pub-0193080271541659";
/* blog */
google_ad_slot = "4394100836";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<br />
<p>So, let's crawl some data out of facebook using R. Don't get too excited though, this is just a weekend whatif project. Anyway, so for example, I want to download some photos where I'm tagged.</p>
<p>First, we need an access token from facebook. I don't know how to get this programmatically, so let's get one manually, log on to facebook and then go to the <a href="https://developers.facebook.com/tools/explorer">Graph API Explorer</a></p>
<a href="http://romainfrancois.blog.free.fr/public/posts/facebook/graph_api_explorer.png"><img src="http://romainfrancois.blog.free.fr/public/posts/facebook/.graph_api_explorer_m.jpg" alt="graph_api_explorer.png" style="margin: 0 auto; display: block;" title="graph_api_explorer.png, janv. 2012" /></a>
<p>Grab the access token and save it into a variable in R</p>
<pre>
access_token <- "************..."
</pre>
<p>Now we need to study the <a href="http://developers.facebook.com/docs/reference/api/">graph api</a> to figure out the url we need to build to do what we want to do, e.g. here we want "me/photos". I've wrapped this into an R function: </p>
<iframe src="http://romainfrancois.blog.free.fr/public/posts/facebook/facebook.R.html" width=500 height=250></iframe>
<p>And then we can use it:</p>
<iframe src="http://romainfrancois.blog.free.fr/public/posts/facebook/dl_photos.R.html" width=500 height=150></iframe>
<p>That's it, I told you it was not that exciting, but it was still worth playing with ...</p>
<p>
Blogroll:
<ul>
<li><a href="http://applyr.blogspot.com/2012/01/mining-facebook-data-most-liked-status.html?spref=tw">
Mining Facebook Data: Most "Liked" Status and Friendship Network</a>.
</li>
<li><a href="http://www.statsravingmad.com/blog/digital-life/download-your-facebook-photos-using-r/"> Download your Facebook photos using R </a></li>
</ul>
</p>
<br/>... And now for solution 17, still using Rcppurn:md5:108b57a97f40ff1a26687e4c0a034b9a2011-12-14T13:35:00+01:00romain francoisRcppRRcpp <p>Here comes yet another sequel of the code optimization problem from the <a href="http://rwiki.sciviews.org/doku.php?id=tips:programming:code_optim2">R wiki</a>, still using <a href="http://dirk.eddelbuettel.com/code/rcpp.html">Rcpp</a>, but with a different strategy this time</p>
<p>Essentially, my <a href="http://romainfrancois.blog.free.fr/index.php?post/2011/11/10/Code-optimization%2C-an-Rcpp-solution">previous version (15)</a> was using stringstream although we don't really need its functionality and it was slowing us down</p>
<p>Also, the characters "i" and "." are always on the same position so we can assign them once and for all</p>
<p>So without further ado, here is attempt 17:</p>
<iframe src="http://romainfrancois.blog.free.fr/public/packages/Rcpp/optim/index17.html" width=500 height=400></iframe>
<p>With quite a speedup from attempt 15:</p>
<pre>
test replications elapsed relative
2 generateIndex17(n) 20 9.363 1.000000
1 generateIndex15(n) 20 17.795 1.900566
</pre>int64: 64 bit integer vectors for Rurn:md5:d600c3cc8419c3367992406f95625fa02011-11-26T10:50:00+01:00romain francoisR packagecplusplusCRANint64packageRRcppRProtoBuf <a href="http://cran.r-project.org/web/packages/int64/index.html"><img src="http://romainfrancois.blog.free.fr/public/packages/int64/google-64.png" alt="google-64.png" style="margin: 0 auto; display: block;" title="google-64.png, nov. 2011" /></a>
<p>The <a href="http://code.google.com/opensource/">Google Open Source Programs Office</a> sponsored me to create the new <a href="http://cran.r-project.org/web/packages/int64/index.html">int64</a> package that has been released to CRAN a few days ago. The package has been mentionned in an article in the <a href="http://google-opensource.blogspot.com/2011/11/bringing-64-bit-data-to-r.html">open source blog from Google</a>. </p>
<p>The package defines classes int64 and uint64 that represent signed and unsigned 64 bit integer vectors. The package also allows conversion of several types (integer, numeric, character, logical) to 64 bit integer vectors, arithmetic operations as well as other standard group generic functions, and reading 64 bit integer vectors as a data.frame column using int64 or uint64 as the colClasses argument. </p>
<p>The package has a <a href="http://cran.r-project.org/web/packages/int64/vignettes/int64.pdf">vignette</a> that details its features, several examples are given in the usual help files. Once again, I've used <a href="http://cran.r-project.org/web/packages/RUnit/index.html">RUnit</a> for quality insurance about the package code</p>
<p><a href="http://cran.r-project.org/web/packages/int64/index.html">int64</a> has been developped so that 64 bit integer vectors are represented using only R data structures, i.e data is not represented as external pointers to some C++ object. Instead, each 64 bit integer is represented as a couple of regular 32 bit integers, each of them carrying half the bits of the underlying 64 bit integer. This was a choice by design so that 64 bit integer vectors can be serialized and used as data frame columns. </p>
<p>The package contains C++ headers that third party packages can used (via LinkingTo: int64) to use the C++ internals. This allows creation and manipulation of the objects in C++. The internals will be documented in another vignette for package developpers who wish to use the internals. For the moment, the main entry point is the C++ template class LongVector. </p>
<p>I'm particularly proud that Google trusted me to sponsor the development of <a href="http://cran.r-project.org/web/packages/int64/index.html">int64</a>. The next versions of packages <a href="http://dirk.eddelbuettel.com/code/rcpp.html">Rcpp</a> and <a href="http://dirk.eddelbuettel.com/code/rprotobuf.html">RProtoBuf</a> take advantage of the facilities of <a href="http://cran.r-project.org/web/packages/int64/index.html">int64</a>, e.g. Rcpp gains wrapping of C++ containers of 64 bit integers as R objects of classes int64 and uint64 and RProtoBuf improves handling of 64 bit integers in protobuf messages. More on this later</p>Code optimization, an Rcpp solutionurn:md5:d6eb76d7737c07f05c91f613c81f4a922011-11-10T18:32:00+01:00romain francoisRRcpp <p><a href="http://tonybreyal.wordpress.com/">Tony Breyal</a> woke up an old code optimization problem in this <a href="http://tonybreyal.wordpress.com/2011/11/02/code-optimization-one-r-problem-ten-solutions-%E2%80%93-now-eleven-2/">blog post</a>, so I figured it was time for an <a href="http://dirk.eddelbuettel.com/code/rcpp.html">Rcpp</a> based solution</p>
<p>This solutions moves down Henrik Bengtsson's idea (which was at the basis of attempt 10) down to C++. The idea was to call sprintf less than the other solutions to generate the strings "001", "002", "003", ...</p>
<iframe src="http://romainfrancois.blog.free.fr/public/packages/Rcpp/generateIndex14_2.html" height=400 width=500></iframe>
<p>We can benchmark this version using the rbenchmark package:</p>
<pre>
> library(rbenchmark)
> n <- 2000
> benchmark(
+ generateIndex10(n),
+ generateIndex11(n),
+ generateIndex12(n),
+ generateIndex13(n),
+ generateIndex14(n),
+ columns =
+ c("test", "replications", "elapsed", "relative"),
+ order = "relative",
+ replications = 20
+ )
test replications elapsed relative
5 generateIndex14(n) 20 21.015 1.000000
3 generateIndex12(n) 20 22.034 1.048489
4 generateIndex13(n) 20 23.436 1.115203
2 generateIndex11(n) 20 23.829 1.133904
1 generateIndex10(n) 20 30.580 1.455151
>
</pre>Rcpp reverse dependency graphurn:md5:40a2bb5d5e546ffaf016ca6dbe2030402011-10-30T10:05:00+01:00romain francoisRcppCRANgraphvizRRcpp <p>I played around with reverse dependencies of <a href="http://dirk.eddelbuettel.com/code/rcpp.html">Rcpp</a>. At the moment, 44 packages depend on <a href="http://dirk.eddelbuettel.com/code/rcpp.html">Rcpp</a> and the number goes up to 53 when counting recusive reverse dependencies.</p>
<p>I've used <a href="http://www.graphviz.org/">graphviz</a> for the representation of the directed graph</p>
<img src="http://romainfrancois.blog.free.fr/public/packages/Rcpp/dep.png" alt="dep.png" style="margin: 0 auto; display: block;" title="dep.png, oct. 2011" />
<p>Here is the code I've used to generate the dot file:</p>
<iframe src="http://romainfrancois.blog.free.fr/public/packages/Rcpp/depends.html" width=550 height=400></iframe>R Bloggers widget in R Graph Galleryurn:md5:69bd1eed6a5d45c48e7e9d6684cc09ea2011-10-11T15:18:00+02:00romain francoisRr bloggersr graph gallery <p>Following <a href="http://romainfrancois.blog.free.fr/index.php?post/2011/10/08/R-Graph-Gallery-widget-in-R-Bloggers">last post</a> about partnership with <a href="http://www.r-bloggers.com/">R Bloggers</a>, <a href="http://www.r-statistics.com/">Tal</a> and I have added a small widget to the gallery main page to present links to recent posts on R Bloggers</p>
<a href="http://romainfrancois.blog.free.fr/public/graphgallery/rbloggers-widget.png"><img src="http://romainfrancois.blog.free.fr/public/graphgallery/.rbloggers-widget_m.jpg" alt="rbloggers-widget.png" style="margin: 0 auto; display: block;" title="rbloggers-widget.png, oct. 2011" /></a>
<p>It uses the wordpress api to grab information about the rss feed generated by R Bloggers and displays links one at a time using the same <a href="http://jquery.malsup.com/cycle/">jquery</a> magic as we've used in the widget that was integrated in R Bloggers a few days ago</p>R Graph Gallery widget in R Bloggersurn:md5:f686b6e49d0ecd5412b5b1837cfb5bff2011-10-08T11:44:00+02:00romain francoisRR Bloggersr graph gallery <p>The <a href="http://www.r-bloggers.com/">R Bloggers</a> website, maintained by <a href="http://www.r-statistics.com/">Tal Galili</a>, aggregates blogs (including mine) from many people of the R community. </p>
<p>Tal and I have been wondering about how to tight R Bloggers with the gallery, supporting each other's website. To that extent, I've made a quick and dirty widget, using <a href="http://jquery.malsup.com/cycle/">the jquery cycle plugin</a> that is now on the right sidebar of R bloggers, inside the <b>related sites</b> box. </p>
<a href="http://romainfrancois.blog.free.fr/public/graphgallery/rbloggers.png"><img src="http://romainfrancois.blog.free.fr/public/graphgallery/.rbloggers_m.jpg" alt="rbloggers.png" style="margin: 0 auto; display: block;" title="rbloggers.png, oct. 2011" /></a>
<p>The widget first chooses 20 items from the gallery at random, and then cycles through them. </p>
<p>This is an initial design made specifically for R Bloggers, but it is quite likely that I will improve on this and make the widget more generic so that other website can use it to advertise for the gallery. </p>Twitter updates on R Graph Galleryurn:md5:ce00bfcaca350969e2dc4b02d4842a052011-10-03T11:05:00+02:00romain francoisRr graph gallery <p>I've added a twitter search widget that searches for the #rgraphgallery hashtag or the url of the gallery on the <a href="http://addictedtor.free.fr/graphiques">front page</a>. </p>
<a href="http://addictedtor.free.fr/graphiques"><img src="http://romainfrancois.blog.free.fr/public/graphgallery/.twitter_m.jpg" alt="twitter.png" style="margin: 0 auto; display: block;" title="twitter.png, oct. 2011" /></a>R Graph Gallery - Donations Welcomeurn:md5:26c00d80abeb5f5f54b4fbada31737632011-09-30T23:46:00+02:00romain francoisRr graph gallery <p>I've added a PayPal button into the <a href="http://addictedtor.free.fr/graphiques">graph</a>, just in case people want to help the development of the website</p>
<a href="http://gallery.r-enthusiasts.com">
<img src="http://romainfrancois.blog.free.fr/public/graphgallery/.paypal_button_m.jpg" alt="paypal_button.png" style="margin: 0 auto; display: block;" title="paypal_button.png, sept. 2011" /></a>
<br/>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0193080271541659";
/* blog */
google_ad_slot = "4394100836";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>Facebook page about the Graph Galleryurn:md5:988a53d317a09fa85ad0361a26926b822011-09-22T20:31:00+02:00romain francoisfacebookRr graph gallery <p>I've just created a
<a href="http://www.facebook.com/pages/R-Graph-Gallery/169231589826661">facebook page</a>
about the <a href="http://addictedtor.free.fr/graphiques/">R Graph Gallery</a></p>
<p>I hope this will improve the experience of the website by making it more social, for example, I anticipate that
people will share their own graphs by sending a picture on the facebook page wall</p>
<p>As part of this, I've added the usual "find us on facebook" widget on the home page of the gallery</p>
<a href="http://addictedtor.free.fr/graphiques"><img src="http://romainfrancois.blog.free.fr/public/graphgallery/.facebook_page_m.jpg" alt="facebook_page.png" style="margin: 0 auto; display: block;" title="facebook_page.png, sept. 2011" /></a>More facebook and google plus on the Graph Galleryurn:md5:720e80fbcc9cc95265f88d7d2117422c2011-09-21T21:42:00+02:00romain francoisRr graph gallery <p>Following up on yesterday's post about <a href="http://romainfrancois.blog.free.fr/index.php?post/2011/09/20/Facebook-like-button-in-Graph-Gallery">facebook like box</a>, I've added some more social things into the gallery. The main page gains a google plus "plus one" button, and each graph page now has a +1 button, a facebook like button, and a facebook comment box</p>
<a href="http://romainfrancois.blog.free.fr/public/Capture_d_ecran_2011-09-21_a_21.40.04.png"><img src="http://romainfrancois.blog.free.fr/public/.Capture_d_ecran_2011-09-21_a_21.40.04_m.jpg" alt="Capture_d_ecran_2011-09-21_a_21.40.04.png" style="margin: 0 auto; display: block;" title="Capture_d_ecran_2011-09-21_a_21.40.04.png, sept. 2011" /></a>Facebook like button in Graph Galleryurn:md5:cfd4e8fdaf1a2dc09a66cee7f32666002011-09-20T22:44:00+02:00romain francoisRR graph gallery <p>I've added <a href="http://facebook.com">facebook</a> like button in the home page of the <a href="http://addictedtor.free.fr/graphiques/">R Graph Gallery</a> and on each image page, i.e. <a href="http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=2">this one</a> which I "like".</p>
<img src="http://romainfrancois.blog.free.fr/public/.Capture_d_ecran_2011-09-20_a_22.46.23_m.jpg" alt="Capture_d_ecran_2011-09-20_a_22.46.23.png" style="margin: 0 auto; display: block;" title="Capture_d_ecran_2011-09-20_a_22.46.23.png, sept. 2011" />now in google+urn:md5:b493d82f1975d4a23af0642db5cdabc72011-07-18T17:23:00+02:00romain francois <p>You can now find me in <a href="https://plus.google.com/104430021204460582047">google+</a>, and still on <a href="http://www.facebook.com/profile.php?id=100001974105739">facebook</a>Rcpp Workshop slidesurn:md5:040811405bb18b0465717a02f33d03782011-04-29T19:23:00+02:00romain francoisRRcppworkshop <p><a href="http://dirk.eddelbuettel.com/">Dirk</a> and I gave a full day Rcpp workshop yesterday in Chicago before the <a href="http://www.rinfinance.com/">R in Finance</a> conference.</p>
<p>The pdfs of the slides are available here: <a href="http://dirk.eddelbuettel.com/papers/rcpp_workshop_part_1_intro.pdf">part 1 (intro)</a>,
<a href="http://dirk.eddelbuettel.com/papers/rcpp_workshop_part_2_details.pdf">part 2 (details)</a>,
<a href="http://dirk.eddelbuettel.com/papers/rcpp_workshop_part_3_advanced.pdf">part 3 (modules)</a>
and <a href="http://dirk.eddelbuettel.com/papers/rcpp_workshop_part_4_applications.pdf">part 4 (applications)</a></p>Rcpp article in JSSurn:md5:8ecac889c9d4f0dade4706c5010082572011-04-17T09:25:00+02:00romain francoisRcpparticlejournaljssRRcpp <p><a href="http://www.jstatsoft.org/"><img src="http://www.jstatsoft.org/images/journal_logo.jpg?1189193120"></img></a></p>
<p><a href="http://www.jstatsoft.org/">The Journal of Statistical Software</a> published our <a href="http://www.jstatsoft.org/v40/i08">Rcpp article</a></p>