Search Results: "Dirk Eddelbuettel"

11 March 2011

Dirk Eddelbuettel: RcppArmadillo 0.2.16

Conrad Sanderson continues an active release schedule for his wonderful Armadillo templated C++ library for linear algebra; release 1.1.8 just came out yesterday. So I made a new release 0.2.16 of RcppArmadillo, our Rcpp-based integration into R. No changes on our side. This new version should now be on most CRAN mirrors. The short NEWS file extract follows below containing just Conrad's entry for 1.1.8.
0.2.16  2011-03-10
    o   Upgraded to Armadillo Version 1.1.8   "Kangaroo Steak"
         * Added floor() and ceil()
         * Added "not a number": math::nan()
         * Added infinity: math::inf()
         * Added standalone is_finite()
         * Faster min(), max(), mean()
         * Bugfix for a corner case with NaNs in min() and max()
And courtesy of CRANberries, here are the diffs to.2.15.
 ChangeLog                                                    6 
 DESCRIPTION                                                 10 
 inst/NEWS                                                   11 
 inst/doc/RcppArmadillo-unitTests.pdf                     binary
 inst/doc/unitTests-results/RcppArmadillo-unitTests.html      6 
 inst/doc/unitTests-results/RcppArmadillo-unitTests.txt      38 -
 inst/include/armadillo                                       2 
 inst/include/armadillo_bits/Cube_meat.hpp                   10 
 inst/include/armadillo_bits/Mat_meat.hpp                    30 -
 inst/include/armadillo_bits/arma_ostream_meat.hpp          119 ++---
 inst/include/armadillo_bits/arma_ostream_proto.hpp           8 
 inst/include/armadillo_bits/arma_version.hpp                 6 
 inst/include/armadillo_bits/arrayops_meat.hpp               39 +
 inst/include/armadillo_bits/arrayops_proto.hpp               5 
 inst/include/armadillo_bits/auxlib_meat.hpp                 10 
 inst/include/armadillo_bits/constants.hpp                  322 +++++++++++---
 inst/include/armadillo_bits/diskio_meat.hpp                 46 +-
 inst/include/armadillo_bits/eglue_core_meat.hpp            345 +++-------------
 inst/include/armadillo_bits/eop_aux.hpp                     16 
 inst/include/armadillo_bits/eop_core_meat.hpp              105 +---
 inst/include/armadillo_bits/eop_core_proto.hpp               6 
 inst/include/armadillo_bits/fn_elem.hpp                     58 ++
 inst/include/armadillo_bits/fn_misc.hpp                     53 ++
 inst/include/armadillo_bits/fn_norm.hpp                     14 
 inst/include/armadillo_bits/format_wrap.hpp                 12 
 inst/include/armadillo_bits/op_max_meat.hpp                 43 -
 inst/include/armadillo_bits/op_mean_meat.hpp                38 -
 inst/include/armadillo_bits/op_min_meat.hpp                 46 +-
 inst/include/armadillo_bits/op_var_meat.hpp                 27 -
 inst/include/armadillo_bits/restrictors.hpp                  9 
 inst/include/armadillo_bits/traits.hpp                      20 
 31 files changed, 782 insertions(+), 678 deletions(-)
More information is on the RcppArmadillo page. Questions, comments etc should go to the rcpp-devel mailing list off the R-Forge page.

4 March 2011

Dirk Eddelbuettel: RcppArmadillo 0.2.14 and 0.2.15

A few days ago Conrad Sanderson released version 1.1.6 of his Armadillo templated C++ library for linear algebra. Accordingly, I made a new release 0.2.14 of RcppArmadillo, our Rcpp-based integration into R which included a few local fixes. However, while I updated SVN at the R-Forge project I didn't update the final tarball so Armadillo 1.1.6 wasn't in it. That is corrected in the 0.2.15 upload which is now on CRAN and its mirrors. The short NEWS file extract for both releases follows, also containing Conrad's entry for 1.1.6. A few minor tweaks were added but no user-visible changes:
0.2.15  2011-03-04
    o   Upgraded to Armadillo Version 1.1.6    Baby Carpet Shark 
         * fixed size matrices and vectors can use auxiliary (external) memory
         * .in_range() can use span() arguments
         * subfields can use span() arguments
0.2.14  2011-03-02
    o   Support Run-Time Type Information (RTTI) on matrices by setting the
        state variable vec_state in Row and Col instantiation, with thanks to
        Conrad Sanderson for the hint
    o   fastLm code simplified further by instantiating the Armadillo matrix
        and vector directly from the SEXP coming from R
    o   inst/doc/Makefile now respects $R_HOME environment variable
And courtesy of CRANberries, here are the diffs to.2.14
 ChangeLog                                                   14 -
 DESCRIPTION                                                  8 
 inst/NEWS                                                   10 
 inst/doc/RcppArmadillo-unitTests.pdf                     binary
 inst/doc/unitTests-results/RcppArmadillo-unitTests.html     10 
 inst/doc/unitTests-results/RcppArmadillo-unitTests.txt      39 +-
 inst/include/armadillo_bits/Col_meat.hpp                    51 +++
 inst/include/armadillo_bits/Col_proto.hpp                    3 
 inst/include/armadillo_bits/Cube_meat.hpp                   52 +++
 inst/include/armadillo_bits/Cube_proto.hpp                   7 
 inst/include/armadillo_bits/Mat_meat.hpp                    51 +++
 inst/include/armadillo_bits/Mat_proto.hpp                   12 
 inst/include/armadillo_bits/Row_meat.hpp                    51 +++
 inst/include/armadillo_bits/Row_proto.hpp                    3 
 inst/include/armadillo_bits/arma_version.hpp                 6 
 inst/include/armadillo_bits/config.hpp                       9 
 inst/include/armadillo_bits/field_meat.hpp                 220 ++++++++++++++--
 inst/include/armadillo_bits/field_proto.hpp                 20 +
 inst/unitTests/runit.RcppArmadillo.R                        16 +
 19 files changed, 521 insertions(+), 61 deletions(-)
and to the previous release 0.2.13, respectivel
 ChangeLog                                                   14 ++++++
 DESCRIPTION                                                  6 +-
 inst/NEWS                                                   11 +++++
 inst/doc/Makefile                                           15 +++++--
 inst/doc/RcppArmadillo-unitTests.pdf                     binary
 inst/doc/unitTests-results/RcppArmadillo-unitTests.html     18 ++++----
 inst/doc/unitTests-results/RcppArmadillo-unitTests.txt      34 ++++++++--------
 inst/include/RcppArmadillo/Col_meat.h                       24 ++++++-----
 inst/include/RcppArmadillo/Row_meat.h                       19 ++++----
 src/fastLm.cpp                                              15 ++-----
 10 files changed, 94 insertions(+), 62 deletions(-)
More information is on the RcppArmadillo page. Questions, comments etc should go to the rcpp-devel mailing list off the R-Forge page.

24 February 2011

Dirk Eddelbuettel: Rcpp 0.9.2

The 0.9.2 release of Rcpp is now on CRAN and Debian. This version contains a build fix for the older 10.5.* version of OS X and its g++ 4.2.1 compiler; we now skip one test that upset it. CRAN builds for OS X should resume. We also added simple configuration support for the Intel Compiler; feedback would be welcome on the list. Lastly, documentation in the vignettes was expanded a little. The NEWS entry is below; more detail is in the ChangeLog file in the package and on the Rcpp Changelog page.
0.9.2   2011-02-23
    o   The unitTest runit.Module.client.package.R is now skipped on older OS
        X releases as it triggers a bug with g++ 4.2.1 or older; OS X 10.6 is
        fine but as it no longer support ppc we try to accomodate 10.5 too
        Thanks to Simon Urbanek for pinning this down and Baptiste Auguie
        and Ken Williams for additonal testing 
    o   RcppCommon.h now recognises the Intel Compiler thanks to a short
        patch by Alexey Stukalov; this turns off Cxx0x and TR1 features too
    o   Three more setup questions were added to the Rcpp-FAQ vignette
    o   One question about RcppArmadillo was added to the Rcpp-FAQ vignette
Thanks to CRANberries, there is also a diff to the previous release 0.9.1. As always, even fuller details are on the Rcpp Changelog page and the Rcpp page which also leads to the downloads, the browseable doxygen docs and zip files of doxygen output for the standard formats. A local directory has source and documentation too. Questions, comments etc should go to the rcpp-devel mailing list off the R-Forge page

23 February 2011

Dirk Eddelbuettel: RQuantLib 0.3.6

A bug-fix release RQuantLib 0.3.6 is now on CRAN and in Debian. RQuantLib combines (some of) the quantitative analytics of QuantLib with the R statistical computing environment and language. There are only two changes to two files where an explicit conversion as per Rcpp::as<double> was called for. A Debian archive rebuild had triggered one of those fails to build from source bug reports as the compiler version seems to be more finicky now than when version 0.3.5 was uploaded in November. No other changes were made. Thanks to CRANberries, there is also a diff to the previous release 0.3.5. Full changelog details, examples and more details about this package are at my RQuantLib page.

19 February 2011

Dirk Eddelbuettel: RcppArmadillo 0.2.13

Yesterday Conrad Sanderson released version 1.1.4 of his Armadillo templated C++ library for linear algebra, so hot on the heels our 0.2.12 release from a few days ago comes version 0.2.13 of RcppArmadillo, our Rcpp-based integration into R. This new version 0.2.13 is now on CRAN and its mirrors. The short NEWS file extract follows, also containing Conrad's entry for 1.1.4:
0.2.13  2011-02-18
    o   Upgraded to Armadillo Version 1.1.4   "Manta Lodge"
         * Faster sort()
         * Updated installation to detect recent versions of Intel's MKL
         * Added interpretation of arbitrary "flat" subcubes as matrices
And courtesy of CRANberries, here is the diff to the previous release 0.2.12:
Diff between RcppArmadillo versions 0.2.12 dated 2011-02-16 and 0.2.13 dated 2011-02-19
 ChangeLog                                                    6 
 DESCRIPTION                                                 14 
 inst/NEWS                                                    8 
 inst/doc/RcppArmadillo-unitTests.pdf                     binary
 inst/doc/unitTests-results/RcppArmadillo-unitTests.html      6 
 inst/doc/unitTests-results/RcppArmadillo-unitTests.txt      36 
 inst/include/armadillo_bits/Col_meat.hpp                    64 +
 inst/include/armadillo_bits/Col_proto.hpp                    3 
 inst/include/armadillo_bits/Cube_meat.hpp                  124 ++
 inst/include/armadillo_bits/Cube_proto.hpp                   7 
 inst/include/armadillo_bits/Mat_meat.hpp                   696 +++++++++++---
 inst/include/armadillo_bits/Mat_proto.hpp                   36 
 inst/include/armadillo_bits/Row_meat.hpp                    62 +
 inst/include/armadillo_bits/Row_proto.hpp                    3 
 inst/include/armadillo_bits/arma_version.hpp                 4 
 inst/include/armadillo_bits/arrayops_meat.hpp               76 -
 inst/include/armadillo_bits/debug.hpp                      254 ++++-
 inst/include/armadillo_bits/field_meat.hpp                  44 
 inst/include/armadillo_bits/field_proto.hpp                  2 
 inst/include/armadillo_bits/fn_accu.hpp                     15 
 inst/include/armadillo_bits/fn_prod.hpp                     10 
 inst/include/armadillo_bits/forward_proto.hpp                8 
 inst/include/armadillo_bits/injector_meat.hpp               70 +
 inst/include/armadillo_bits/injector_proto.hpp               4 
 inst/include/armadillo_bits/op_sort_meat.hpp               242 ++---
 inst/include/armadillo_bits/op_sort_proto.hpp               15 
 inst/include/armadillo_bits/span.hpp                        72 +
 inst/include/armadillo_bits/subview_cube_meat.hpp          759 +++++++++++++---
 inst/include/armadillo_bits/subview_cube_proto.hpp          19 
 inst/include/armadillo_bits/subview_field_meat.hpp          83 +
 inst/include/armadillo_bits/subview_field_proto.hpp         11 
 inst/include/armadillo_bits/subview_meat.hpp               118 +-
 inst/include/armadillo_bits/subview_proto.hpp               21 
 33 files changed, 2113 insertions(+), 779 deletions(-)
More information is on the RcppArmadillo page. Questions, comments etc should go to the rcpp-devel mailing list off the R-Forge page.

16 February 2011

Dirk Eddelbuettel: RcppArmadillo 0.2.12

A new version 1.1.2 of Conrad Sanderson's Armadillo templated C++ library for linear algebra came out a couple of days ago. This has now been wrapped into a new version 0.2.12 of RcppArmadillo, our Rcpp-based integration into R. The short NEWS file extract follows, also containing Conrad's entry for 1.1.2:
0.2.12  2011-02-15
    o   Upgraded to Armadillo Version 1.1.2    Flood Kayak 
         * Faster prod()
         * Faster solve() for compound expressions
         * Fix for compilation using GCC's C++0x mode
         * Fix for matrix handling by subcubes
And courtesy of CRANberries, here is the diff to the previous release 0.2.11:
Diff between RcppArmadillo versions 0.2.11 dated 2011-01-08 and 0.2.12 dated 2011-02-16
 RcppArmadillo-0.2.11/RcppArmadillo/inst/include/armadillo_bits/syslib_proto.hpp             only
 RcppArmadillo-0.2.12/RcppArmadillo/ChangeLog                                                    6 
 RcppArmadillo-0.2.12/RcppArmadillo/DESCRIPTION                                                 17 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/NEWS                                                   12 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/doc/RcppArmadillo-unitTests.pdf                     binary
 RcppArmadillo-0.2.12/RcppArmadillo/inst/doc/unitTests-results/RcppArmadillo-unitTests.html      6 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/doc/unitTests-results/RcppArmadillo-unitTests.txt      30 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/README                                          1 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo                                      13 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/Base.hpp                        15 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/Col_meat.hpp                    14 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/Col_proto.hpp                    8 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/Cube_meat.hpp                    6 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/Mat_meat.hpp                    20 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/Mat_proto.hpp                   15 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/Row_meat.hpp                    14 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/Row_proto.hpp                    8 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/arma_config.hpp                 10 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/arma_version.hpp                 8 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/arrayops_meat.hpp            only
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/arrayops_proto.hpp             448 +---------
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/auxlib_meat.hpp                 63 -
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/auxlib_proto.hpp                10 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/compiler_setup.hpp               8 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/config.hpp                      20 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/debug.hpp                       27 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/fn_conv_to.hpp                  60 -
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/fn_prod.hpp                     40 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/glue_solve_meat.hpp             10 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/glue_solve_proto.hpp             4 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/injector_meat.hpp                6 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/op_dot_meat.hpp                  2 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/op_prod_meat.hpp                29 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/op_reshape_meat.hpp              8 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/op_trans_meat.hpp                2 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/op_trimat_meat.hpp               4 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/podarray_meat.hpp                4 
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/subview_cube_meat.hpp           50 -
 RcppArmadillo-0.2.12/RcppArmadillo/inst/include/armadillo_bits/subview_meat.hpp                 8 
 39 files changed, 339 insertions(+), 667 deletions(-)
More information is on the RcppArmadillo page. Questions, comments etc should go to the rcpp-devel mailing list off the R-Forge page.

15 February 2011

Dirk Eddelbuettel: Rcpp 0.9.1

A new release 0.9.1 of Rcpp went to CRAN and Debian yesterday. This version contains mostly bug-fixes and rather few enhancements. The changes are mostly 'internal fixes' and not user-facing; they mostly address some issues in memory management which, while not tripping up the unit tests or common usage, caused trouble for advanced Rcpp modules use and repeated memory allocation / deallocation. This bit Doug Bates repeatedly, and he put his head down and debugged the issue. A number of changes fairly deep-down in Rcpp (as well as in R-devel) later, this looks much better and we owe him a hearfelt Thank You! A big Thanks! also goes to Luke Tierney who out some new memory debugging code into R-devel which the --enable-strict-barrier in R 2.13.0 (due in April) will enable. A related fix is also in R 2.12.2 due on the 25th. The NEWS entry is below; more detail is in the ChangeLog file in the package.
0.9.1   2011-02-14
    o   A number of internal changes to the memory allocation / protection of
        temporary objects were made---with a heartfelt "Thank You!" to both
        Doug Bates for very persistent debugging of Rcpp modules code, and to
        Luke Tierney who added additional memory allocation debugging tools
        to R-devel (which will be in R 2.13.0 and may also be in R 2.12.2)
        
    o   Removed another GNU Make-specific variable from src/Makevars in order
        to make the build more portable; this was noticed on FreeBSD
    o   On *BSD, do not try to compute a stack trace but provide file and
        line number (which is the same behaviour as implemented in Windows)
    o   Fixed an int conversion bug reported by Daniel Sabanes Bove on r-devel,
        added unit test as well
    
    o   Added unit tests for complex-typed vectors (thanks to Christian Gunning)
    
    o   Expanded the Rcpp-quickref vignette (with thanks to Christian Gunning)
    o   Additional examples were added to the Rcpp-FAQ vignette
Thanks to CRANberries, there is also a diff to the previous release 0.9.0. As always, even fuller details are on the Rcpp Changelog page and the Rcpp page which also leads to the downloads, the browseable doxygen docs and zip files of doxygen output for the standard formats. A local directory has source and documentation too. Questions, comments etc should go to the rcpp-devel mailing list off the R-Forge page

6 February 2011

Dirk Eddelbuettel: Wynton Marsalis and the Jazz at Lincoln Center Orchestra

Went to the CSO on Friday night to see the annual concert of Wynton Marsalis and the Jazz at Lincoln Center Orchestra. This year's concert featured one set with four pieces from the new Vitoria Suite album---see here for a raving review. Those pieces were indeed very nice and I may to grab the disc to hear the full suite. Thhis was followed by a number of pieces composed or arranged by different band members. All in all a great concert. Hard not to love when you twelve-man strong brass section featuring four trumpets, three trombones, five saxophones supported by a nice rhythm section of three. Recommended.

23 January 2011

Dirk Eddelbuettel: CRANberries is now tweeting

The CRANberries service (which reports on new and updated CRAN packages for the R language and environment) is now tweeting about new packages. Simply follow @CRANberriesFeed to receive theses messages. For the technically minded, adding this to the existing 200-line program which runs all of CRANberries was very easy. CRANberries relies only on R itself and a few Unix tools like diffstat as well as the simple blosxom txt-to-html/rss 'blog compiler'. The tweeting itself is now done by this new function
tweetNewBlogEntry <- function(curPkg, curVer, reposurl)  
    ## tests reveal that pipe(), cat(), close() is easiest
    ## to send multiple messages, may need --background option
    con <- pipe("bti --config bti.conf", "w")
    cat("New CRAN package", curPkg, "with initial version", curVer, " http://goo.gl/pgljT\n", file=con)
    close(con)
 
which simply pipes the message in Greg KH's bti program (which is now a new dependency). Special thanks to its Debian maintainer Gregor Herrmann for some helpful emails; I am using the newest release 0.29 which itself needs liboauth0. Once OAuth tokens are set-up (and see here for how to do that) all we need is the three-liner above. At this point I am not too sure what to do about updated packages. One message per updated package seems too noisy. To be seen---comments or suggestions welcome.

19 January 2011

Dirk Eddelbuettel: RcppBDT 0.1.0

The family of Rcpp packages just grew by one: the first 0.1.0 release of RcppBDT is now on CRAN. RcppBDT stands for Rcpp Boost Date_Time. It employs what we call Rcpp modules: a mechanism which provides easier ways to expose C++ functions and classes to R (and which bears some resemblance to Boost.Python---see this vignette about Rcpp modules for more details). And thus RcppBDT provides R users with access to (some) Boost Date.Time functionality. I used Boost Date.Time because it is widely known, useful and well tested. It can also be used in pure template mode not requiring linking (if one foregoes string parsing and formatting which is fine here as we get this from R already; it can be added via a #define in the header file). With that, the package is rather portable as it only needs to find the Boost headers. (And no, I have not yet added a configure option for that.) Basic usage follows Rcpp modules and provides the C++ class via a Reference Class in R. That means using a new constructor and assessing functions via the $ operator. Here is an example:
R> library(RcppBDT)
Creating a new generic function for "print" in "RcppBDT"
Creating a new generic function for "format" in "RcppBDT"
R> d <- new(bdtMod$date, 2011, 1, 18)
R> format(d)
[1] "2011-01-18"
R>
Not very exiting yet: we create a date, using explicit year, months and date arguments and then format it. Something more useful follows:
R> d$getDayOfWeek()
[1] 2
R> d$getModJulian()
[1] 55579
R> d$getFirstOfNextMonth()
[1] "2011-02-01"
R>
We can use accessors to extracts parts of the date, or use functions to convert the date to different representations such as a modified Julian date. Moreover, given a date, we can apply helper functions such as get me the date of the beginning of the next month. More interesting still are helper functions such as the ones below. Note that this also shows the alternate access method using wrapper functions I added for the package, this may be more familiar to most R users:
R> getNthDayOfWeek(third, Wed, Dec, 2010)
[1] "2010-12-15"
R> getLastDayOfWeekInMonth(Sat, Dec, 2010)
[1] "2010-12-25"
R> getFirstDayOfWeekInMonth(Sat, Dec, 2010)
[1] "2010-12-04"
R> getFirstDayOfWeekAfter(Wed, as.Date("2010-12-31"))
[1] "2011-01-05"
R>
This uses some of the constants Jan, Feb, ... , Dec; Sun, Mon, ..., Sat and first ... fifth defined in the package; normal integers can also be used. The third Wednesday in a month is also known as the IMM Date to Finance-heads; the example was borrowed from Whit's earlier rboostdatetime code on github. More examples are in the demo available with the package and accessible via demo(RcppBDT) once you install the package. As always, feedback would be welcome, both on the usefulness (or lack thereof) of the Boost Date.Time functionality as well as on the Rcpp modules wrapping. Additional Boost Date.Time functionality (durations, times, ...) may be added; contributions would be welcome. The rcpp-devel mailing list off the R-Forge page for Rcpp is the best place to start a discussion.

17 January 2011

Dirk Eddelbuettel: Keeping simple things simple

My friend Jeff deserves a sincere congratulation for finally unveiling his rebranded R consultancy Lemnica. One notable feature of the new website is a section called esoteric R which discusses less frequently-visited corners of the R world. It even boasts its own CRAN package esotericR with the example sources. esoteric R currently holds two articles. Jeff had sent me the one about introducing closures a while back, and I like it and may comment at another time. What caught me by surprise when Lemnica finally opened was the other article: R calling C. It is a fine article motivated by all the usual reasons that are e.g. mentioned in the Google Tech Talk which Romain and I gave last October about our work around Rcpp. But it is just not simple. Allow me to explain. When Jeff showed this C language file
#include <R.h>
#include <Rinternals.h>
SEXP esoteric_rev (SEXP x)  
  SEXP res;
  int i, r, P=0;
  PROTECT(res = allocVector(REALSXP, length(x))); P++;
  for(i=length(x), r=0; i>0; i--, r++)  
     REAL(res)[r] = REAL(x)[i-1];
   
  copyMostAttrib(x, res);
  UNPROTECT(P);
  return res;
 
and then needs several paragraphs to explain what is going on, what is needed to compile and then how to load it --- I simply could not resist. Almost immediately, I emailed back to him something as simple as this using both our Rcpp package as well as the wonderful inline package by Oleg which Romain and I more or less adopted:
library(inline)  ## for cxxfunction()
src <- 'Rcpp::NumericVector x = Rcpp::NumericVector(xs);
        std::reverse(x.begin(), x.end());
        return(x);'
fun <- cxxfunction(signature(xs="numeric"), body=src, plugin="Rcpp")
fun( seq(0, 1, 0.1) )
Here we load inline, and then define a three-line C++ program using facilities from our Rcpp package. All we need to revert a vector is to first access its R object in C++ by instantiating the R vector as a NumericVector. These C++ classes then provide iterators which are compatible with the Standard Template Library (STL). So we simply call the STL function reverse pointing the beginning and end of the vector, and are done! Rcpp then allows us the return the C++ vector which it turns into an R vector. Efficient in-place reversal, just like Jeff had motivated, in three lines. Best of all, we can execute this from within R itself:
R> library(inline)  ## for cxxfunction()
R> src <- 'Rcpp::NumericVector x = Rcpp::NumericVector(xs);
+         std::reverse(x.begin(), x.end());
+         return(x);'
R> fun <- cxxfunction(signature(xs="numeric"), body=src, plugin="Rcpp")
R> fun( seq(0, 1, 0.1) )
 [1] 1.0 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0.0
R>
Lastly, Jeff shows a more complete example wherein a new vector is created, and any potential attributes are copied as well. Naturally, we can do that too. First, we used clone() to make a deep copy (ie forcing creation of a new object rather than a mere proxy) and use the same R API function he accessed---but it our case both prefixed with ::Rf_ for R remapping (to protect clashed with other functions with identical names) and a global namespace identifier (as it is a global C function from R).
R> library(inline)
R> src <- 'Rcpp::NumericVector x = Rcpp::clone<Rcpp::NumericVector>(xs);
+         std::reverse(x.begin(), x.end());
+         ::Rf_copyMostAttrib(xs, x);
+         return(x);'
R> fun <- cxxfunction(signature(xs="numeric"), body=src, plugin="Rcpp")
R> obj <- structure(seq(0, 1, 0.1), obligatory="hello, world!")
R> fun(obj)
 [1] 1.0 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0.0
attr(,"obligatory")
[1] "hello, world!"
R> obj
 [1] 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
attr(,"obligatory")
[1] "hello, world!"
R>
Both the obj variable and the new copy contain the desired data attribute, the new copy is reversed, the original is untouched---and all in four lines of C++ called via one inline call. I have now been going on for over one hundred lines yet I never had to mention memory management, pointers, PROTECT or other components of the R API for C. Hopefully, this short writeup provided an idea of why Romain and I think Rcpp is the way to go for creating C/C++ functions for extending and enhancing R.

16 January 2011

Dirk Eddelbuettel: Plotting overbought / oversold regions in R

The good folks at Bespoke Investment Group frequently show charts of so-called overbought or oversold levels; see e.g. here for the most recent global markets snapshot. Classifying markets as overbought or oversold is a popular heuristic. It starts from computing a rolling smoothed estimate of the prices, usually via a (exponential or standard) moving average over a suitable number of days (where Bespoke uses 50 days, see here). This is typically coupled with a (simple) rolling standard deviation. Overbought and oversold regions are then constructed by taking the smoothed mean plus/minus one and two standard deviations. Doing this is in R is pretty easy thanks to the combination of R's rich base functions and its add-on packages from CRAN. Below is a simply function I wrote a couple of months ago---and I figured I might as well release. It relies on the powerful packages quantmod and TTR by my pals Jeff Ryan and Josh Ulrich, respectively.
## plotOBOS -- displaying overbough/oversold as eg in Bespoke's plots
##
## Copyright (C) 2010 - 2011  Dirk Eddelbuettel
##
## This is free software: you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 2 of the License, or
## (at your option) any later version.
suppressMessages(library(quantmod))     # for getSymbols(), brings in xts too
suppressMessages(library(TTR))          # for various moving averages
plotOBOS <- function(symbol, n=50, type=c("sma", "ema", "zlema"), years=1, blue=TRUE)  
    today <- Sys.Date()
    X <- getSymbols(symbol, src="yahoo", from=format(today-365*years-2*n), auto.assign=FALSE)
    x <- X[,6]                          # use Adjusted
    type <- match.arg(type)
    xd <- switch(type,                  # compute xd as the central location via selected MA smoother
                 sma = SMA(x,n),
                 ema = EMA(x,n),
                 zlema = ZLEMA(x,n))
    xv <- runSD(x, n)                   # compute xv as the rolling volatility
    strt <- paste(format(today-365*years), "::", sep="")
    x  <- x[strt]                       # subset plotting range using xts' nice functionality
    xd <- xd[strt]
    xv <- xv[strt]
    xyd <- xy.coords(.index(xd),xd[,1]) # xy coordinates for direct plot commands
    xyv <- xy.coords(.index(xv),xv[,1])
    n <- length(xyd$x)
    xx <- xyd$x[c(1,1:n,n:1)]           # for polygon(): from first point to last and back
    if (blue)  
        blues5 <- c("#EFF3FF", "#BDD7E7", "#6BAED6", "#3182BD", "#08519C") # cf brewer.pal(5, "Blues")
        fairlylight <- rgb(189/255, 215/255, 231/255, alpha=0.625) # aka blues5[2]
        verylight <- rgb(239/255, 243/255, 255/255, alpha=0.625) # aka blues5[1]
        dark <- rgb(8/255, 81/255, 156/255, alpha=0.625) # aka blues5[5]
      else  
        fairlylight <- rgb(204/255, 204/255, 204/255, alpha=0.5)         # grays with alpha-blending at 50%
        verylight <- rgb(242/255, 242/255, 242/255, alpha=0.5)
        dark <- 'black'
     
    plot(x, ylim=range(range(xd+2*xv, xd-2*xv, na.rm=TRUE)), main=symbol, col=fairlylight) 		# basic xts plot
    polygon(x=xx, y=c(xyd$y[1]+xyv$y[1], xyd$y+2*xyv$y, rev(xyd$y+xyv$y)), border=NA, col=fairlylight) 	# upper
    polygon(x=xx, y=c(xyd$y[1]-1*xyv$y[1], xyd$y+1*xyv$y, rev(xyd$y-1*xyv$y)), border=NA, col=verylight)# center
    polygon(x=xx, y=c(xyd$y[1]-xyv$y[1], xyd$y-2*xyv$y, rev(xyd$y-xyv$y)), border=NA, col=fairlylight) 	# lower
    lines(xd, lwd=2, col=fairlylight)   # central smooted location
    lines(x, lwd=3, col=dark)           # actual price, thicker
    invisible(NULL)
 
After downloading data and computing the rolling smoothed mean and standard deviation, it really is just a matter of plotting (appropriate) filled polygons. Here I used colors from the neat RColorBrewer package with some alpha blending. Colors can be turned off via an option to the function; ranges, data length and type of smoother can also be picked. To call this in R, simply source the file and the call, say, plotOBOS("^GSPC", years=2) which creates a two-year plot of the SP500 as shown here: Example chart of overbought/oversold levels from plotOBOS() function This shows the market did indeed bounce off the oversold lows nicely on a few occassions in 2009 and 2010 --- but also continued to slide after hitting the condition. Nothing is foolproof, and certainly nothing as simple as this is, so buyer beware. But it may prove useful in conjunction with other tools. The code for the script is here and of course available under GPL 2 or later. I'd be happy to help incorporate it into some other finance package. Lastly, if you read this post this far, also consider our R / Finance conference coming at the end of April.

Edit: Corrected several typos with thanks to Josh.

15 January 2011

Dirk Eddelbuettel: Allen Toussaint with Don Byron and Nicholas Payton

Lisa snagged us some sort of subscription to the CSO's jazz series and last night was a first concert resulting from this. In town were Allen Toussaint with a three piece rhythm section as well as Don Byron (also here) on clarinet and tenor saxophone, and Nicholas Payton (also here) on trumpet. Given Allen Toussaint's live-long association with New Orleans, there was a lot of music inspired by the town, including a modern rendition of an old Sidney Bechet tune as well as other material came from his most recent album The Bright Mississippi. And, given Allen Toussaint's fame in Rhythm and Blues circles, there was lot of R&B too. I found the program to be a little uneven and unbalanced that way---but it was still a great show, and he surely brought the house down. He is a charming old school performer, and maybe the audience warmed his heart right before the concert started with a quick Happy Birthday rendition as yesterday was in fact his this 73rd birthday! Don Byron and Nicholas Payton were, as expected, stellar in their own right. A nice night out.

12 January 2011

Dirk Eddelbuettel: RProtoBuf 0.2.2

Thanks to two patches by Murray Stokely, we have a nice new minor release 0.2.2 of RProtoBuf out on CRAN. RProtoBuf provides GNU R bindings for the Google Protobuf data encoding library used and released by Google. The NEWS file entry follows below:
0.2.2   2011-01-11
   o    Applied two patches by Murray Stokely which 
         - correct a typo preventing some functions from being called, 
         - add bounds checking in call to google protobuf library, 
         - add a new name method 
         - add a tiny unit test for the above
         - add more graceful error handling
         - add support for import patterns other than .proto$, 
         - add simple reading file that does not exist (exception) test
         - add simple repeated field unit test
And courtesy of CRANberries, here is the diff to the previous release 0.2.1:
 ChangeLog                                               35 
 DESCRIPTION                                              8 
 R/00classes.R                                           11 
 R/internals.R                                            7 
 R/wrapper_EnumDescriptor.R                               6 
 inst/NEWS                                               12 
 inst/THANKS                                          only
 inst/doc/Makefile                                        4 
 inst/doc/RProtoBuf-quickref.pdf                      binary
 inst/doc/RProtoBuf-unitTests.pdf                     binary
 inst/doc/RProtoBuf.pdf                                2362 +++++++++-----------
 inst/doc/unitTests-results/RProtoBuf-unitTests.html     20 
 inst/doc/unitTests-results/RProtoBuf-unitTests.txt      23 
 inst/unitTests/runit.addressbook.R                      11 
 inst/unitTests/runit.enums.R                         only
 inst/unitTests/runit.golden.message.R                    7 
 inst/unitTests/runit.import.R                        only
 man/EnumDescriptor-class.Rd                             42 
 man/EnumValueDescriptor-class.Rd                        23 
 man/readProtoFiles.Rd                                    3 
 src/DescriptorPoolLookup.cpp                            26 
 src/S4_classes.h                                         6 
 src/wrapper_EnumDescriptor.cpp                          25 
 src/wrapper_EnumValueDescriptor.cpp                     25 
 24 files changed, 1357 insertions(+), 1299 deletions(-)
As always, there is more information at the RProtoBuf page which has a draft package vignette, a 'quick' overview vignette and a unit test summary vignette. Questions, comments etc should go to the rprotobuf mailing list off the RProtoBuf page at R-Forge.

8 January 2011

Dirk Eddelbuettel: RcppArmadillo 0.2.11

Just before Xmas, Conrad Sanderson released version 1.1.0 of Armadillo, his templated C++ library for linear algebra. Which I only noticed this week, so here comes version 0.2.11 of RcppArmadillo, our Rcpp-based integration into R. The only other change is the addition of an unexported function SHLIB which can be used to compiled a single source file into a loadable shared library file for R, while automagically find Rcpp and RcppArmadillo headers and the Rcpp library. The short NEWS file extract follows, also containing Conrad's entry for 1.1.0:
0.2.11  2011-01-06
    o   Upgraded to Armadillo Version 1.1.0    Climate Vandal 
         * Extended submatrix views, including access to elements whose
           indices are specified in a separate vector
         * Added handling of raw binary files by save/load functions
         * Added cumsum()
         * Added interpretation of matrices as triangular via
           trimatu()/trimatl() 
         * Faster solve(), inv() via explicit handling of triangular matrices 
         * The stream for logging of errors and warnings can now be changed 
    o   New unexported R function SHLIB, a small wrapper around R CMD SHLIB,
        which can be used as   Rscript -e "RcppArmadillo:::SHLIB('foo.cpp')"
And courtesy of CRANberries, here is the diff to the previous release 0.2.10:
 ChangeLog                                                   17 
 DESCRIPTION                                                 12 
 R/SHLIB.R                                                only
 inst/NEWS                                                   13 
 inst/doc/Makefile                                            5 
 inst/doc/RcppArmadillo-unitTests.pdf                     binary
 inst/doc/unitTests-results/RcppArmadillo-unitTests.html     16 
 inst/doc/unitTests-results/RcppArmadillo-unitTests.txt      34 
 inst/include/armadillo                                       9 
 inst/include/armadillo_bits/Col_meat.hpp                    25 
 inst/include/armadillo_bits/Col_proto.hpp                    5 
 inst/include/armadillo_bits/Cube_meat.hpp                   54 +
 inst/include/armadillo_bits/Cube_proto.hpp                   7 
 inst/include/armadillo_bits/Mat_meat.hpp                   469 ++++++++++++
 inst/include/armadillo_bits/Mat_proto.hpp                   54 +
 inst/include/armadillo_bits/Proxy.hpp                       63 +
 inst/include/armadillo_bits/Row_meat.hpp                    25 
 inst/include/armadillo_bits/Row_proto.hpp                    3 
 inst/include/armadillo_bits/arma_version.hpp                11 
 inst/include/armadillo_bits/auxlib_meat.hpp                102 ++
 inst/include/armadillo_bits/auxlib_proto.hpp                13 
 inst/include/armadillo_bits/debug.hpp                      101 +-
 inst/include/armadillo_bits/diskio_meat.hpp                280 +++++++
 inst/include/armadillo_bits/diskio_proto.hpp                 9 
 inst/include/armadillo_bits/field_meat.hpp                  23 
 inst/include/armadillo_bits/field_proto.hpp                  3 
 inst/include/armadillo_bits/fn_cumsum.hpp                only
 inst/include/armadillo_bits/fn_dot.hpp                      66 +
 inst/include/armadillo_bits/fn_elem.hpp                  only
 inst/include/armadillo_bits/fn_inv.hpp                      27 
 inst/include/armadillo_bits/fn_max.hpp                      17 
 inst/include/armadillo_bits/fn_mean.hpp                     17 
 inst/include/armadillo_bits/fn_median.hpp                   15 
 inst/include/armadillo_bits/fn_min.hpp                      21 
 inst/include/armadillo_bits/fn_misc.hpp                    604 ----------------
 inst/include/armadillo_bits/fn_prod.hpp                     15 
 inst/include/armadillo_bits/fn_solve.hpp                    22 
 inst/include/armadillo_bits/fn_stddev.hpp                   15 
 inst/include/armadillo_bits/fn_sum.hpp                      25 
 inst/include/armadillo_bits/fn_trimat.hpp                only
 inst/include/armadillo_bits/fn_var.hpp                      15 
 inst/include/armadillo_bits/forward_proto.hpp                7 
 inst/include/armadillo_bits/glue_solve_meat.hpp             32 
 inst/include/armadillo_bits/glue_solve_proto.hpp            12 
 inst/include/armadillo_bits/lapack_proto.hpp               103 ++
 inst/include/armadillo_bits/op_cumsum_meat.hpp           only
 inst/include/armadillo_bits/op_cumsum_proto.hpp          only
 inst/include/armadillo_bits/op_dot_meat.hpp                 46 +
 inst/include/armadillo_bits/op_dot_proto.hpp                 9 
 inst/include/armadillo_bits/op_find_meat.hpp                59 -
 inst/include/armadillo_bits/op_inv_meat.hpp                 13 
 inst/include/armadillo_bits/op_inv_proto.hpp                14 
 inst/include/armadillo_bits/op_trimat_meat.hpp           only
 inst/include/armadillo_bits/op_trimat_proto.hpp          only
 inst/include/armadillo_bits/podarray_meat.hpp                7 
 inst/include/armadillo_bits/span.hpp                         9 
 inst/include/armadillo_bits/subview_elem1_meat.hpp       only
 inst/include/armadillo_bits/subview_elem1_proto.hpp      only
 inst/include/armadillo_bits/subview_meat.hpp               321 ++++++--
 inst/include/armadillo_bits/subview_proto.hpp                1 
 inst/include/armadillo_bits/typedef.hpp                      4 
 inst/include/armadillo_bits/unwrap.hpp                     135 +++
 62 files changed, 2155 insertions(+), 829 deletions(-)
More information is on the RcppArmadillo page. Questions, comments etc should go to the rcpp-devel mailing list off the R-Forge page.

5 January 2011

Dirk Eddelbuettel: The kindness of strangers

A couple of days ago, an email arrived in which I am kindly asked to provide my PayPal coordinates. And before you dear reader start to laugh, it was actually perfectly genuine and came from a very happy user of the Finance::YahooQuote Perl module. DJ Padzensky wrote this well over a decade ago, and I first introduced and then maintained it as a package in Debian for what is now almost twelve years. I have also been acting as upstream maintainer for the last eight or so years providing the occassional patch to keep up with changes at the Yahoo! server side. After a short reflection, I decided to keep it simple. I undusted a wishlist I had once created over at Amazon, yet never publicised. And amazingly, within minutes of minutes of passing the URL on, I received a cheerful email stating that three books are their merry way. Appropriately enough, two were from Springer's useR! series and another one was a brand new GPU programming title. And they all arrived yesterday. I am still stunned. So with that, my time to say thanks! This was a genuinely nice gesture, and I really appreciate it. I have been doing open source work for over fifteen years now, and I would not still be doing it if I did not enjoy it myself. I continue to learn a lot in the process, and have had a chance to meet lot interesting folks. Yet it is also nice to get a little Thanks every now and them.

31 December 2010

Dirk Eddelbuettel: R / Finance 2011 Call for Papers: Updated and expanded

One week ago, I sent the updated announcement below to the r-sig-finance list; this was kindly blogged about by fellow committee member Josh and by our pal Dave @ REvo. By now. I also updated the R / Finance conference website. So to round things off, a quick post here is in order as well. It may even get a few of the esteemed reader to make a New Year's resolution about submitting a paper :) Dear R / Finance community, The preparations for R/Finance 2011 are progressing, and due to favourable responses from the different sponsors we contacted, we are now able to offer

  1. a competition for best paper, which given the focus of the conference will award for both an 'academic' paper and an 'industry' paper
  2. availability of travel grants for up to two graduate students provided suitable papers were accepted for presentations
More details are below in the updated Call for Papers. Please feel free to re-circulate this Call for Papers with collegues, students and other associations. Cheers, and Season's Greeting, Dirk (on behalf of the organizing / program committee) Call for Papers: R/Finance 2011: Applied Finance with R April 29 and 30, 2011 Chicago, IL, USA The third annual R/Finance conference for applied finance using R will be held this spring in Chicago, IL, USA on April 29 and 30, 2011. The two-day conference will cover topics including portfolio management, time series analysis, advanced risk tools, high-performance computing, market microstructure and econometrics. All will be discussed within the context of using R as a primary tool for financial risk management, portfolio construction, and trading. Complete papers or one-page abstracts (in txt or pdf format) are invited to be submitted for consideration. Academic and practitioner proposals related to R are encouraged. We welcome submissions for full talks, abbreviated lightning talks, and for a limited number of pre-conference (longer) seminar sessions. Presenters are strongly encouraged to provide working R code to accompany the presentation/paper. Data sets should also be made public for the purposes of reproducibility (though we realize this may be limited due to contracts with data vendors). Preference may be given to presenters who have released R packages. The conference will award two $1000 prizes for best paper: one for best practitioner-oriented paper and one for best academic-oriented paper. Further, to defray costs for graduate students, two travel and expense grants of up to $500 each will be awarded to graduate students whose papers are accepted. To be eligible, a submission must be a full paper; extended abstracts are not eligible. Please send submissions to: committee at RinFinance.com The submission deadline is February 15th, 2011. Early submissions may receive early acceptance and scheduling. The graduate student grant winners will be notified by February 23rd, 2011. Submissions will be evaluated and submitters notified via email on a rolling basis. Determination of whether a presentation will be a long presentation or a lightning talk will be made once the full list of presenters is known. R/Finance 2009 and 2010 included attendees from around the world and featured keynote presentations from prominent academics and practitioners. 2009-2010 presenters names and presentations are online at the conference website. We anticipate another exciting line-up for 2011---including keynote presentations from John Bollinger, Mebane Faber, Stefano Iacus, and Louis Kates. Additional details will be announced via the conference website as they become available. For the program committee:
Gib Bassett, Peter Carl, Dirk Eddelbuettel, Brian Peterson,
Dale Rosenthal, Jeffrey Ryan, Joshua Ulrich

25 December 2010

Dirk Eddelbuettel: Rcpp 0.9.0 announcement

The text below went out as a post to the r-packages list a few days ago, but I thought it would make sense to post it on the blog too. So with a little html markup... Summary Version 0.9.0 of the Rcpp package is now on CRAN and its mirrors. This release marks another step in the development of the package, and a few key points are highlighted below. More details are in the NEWS and ChangeLog files included in the package. Overview Rcpp is an R package and associated C++ library that facilitates integration of C++ code in R packages. The package features a complete set of C++ classes (Rcpp::IntegerVector, Rcpp:NumericVector, Rcpp::Function, Rcpp::Environment, ...) that makes it easier to manipulate R objects of matching types (integer vectors, functions, environments, etc ...). Rcpp takes advantage of C++ language features such as the explicit constructor / destructor lifecycle of objects to manage garbage collection automatically and transparently. We believe this is a major improvement over use of PROTECT / UNPROTECT. When an Rcpp object is created, it protects the underlying SEXP so that the garbage collector does not attempt to reclaim the memory. This protection is withdrawn when the object goes out of scope. Moreover, users generally do not need to manage memory directly (via calls to new / delete or malloc / free) as this is done by the Rcpp classes or the corresponding STL containers. A few key points about Rcpp:

Several key features were added during the 0.8.* cycles and are described below. Rcpp sugar Rcpp now provides syntactic sugar: vectorised expressions at the C++ level which are motivated by the corresponding R expressions. This covers operators (binary arithmetic, binary logical, unary), functions (producing single logical results, mathematical functions and d/p/q/r statistical functions). Examples comprises anything from ifelse() to pmin()/pmax() or A really simply example is a function
    SEXP foo( SEXP xx, SEXP yy) 
        NumericVector x(xx), y(yy) ;
        return ifelse( x < y, x*x, -(y*y) ) ;
     
which deploys the sugar 'ifelse' function modeled after the corresponding R function. Another simple example is
    double square( double x) 
        return x*x ;
     
    SEXP foo( SEXP xx ) 
        NumericVector x(xx) ;
        return sapply( x, square ) ;
     
where use the sugar function 'sapply' to sweep a simple C++ function which operates elementwise across the supplied vector. The Rcpp-sugar vignette describes sugar in more detail. Rcpp modules Rcpp modules are inspired by Boost.Python and make exposing C++ functions or classes to R even easier. A first illustration is provided by this simple C++ code snippet
    const char* hello( const std::string& who ) 
        std::string result( "hello " ) ;
        result += who ;
        return result.c_str() ;
     
    RCPP_MODULE(yada) 
        using namespace Rcpp ;
        function( "hello", &hello ) ;
     
which (after compiling and loading) we can access in R as
    yada <- Module( "yada" )
    yada$hello( "world" )
In a similar way, C++ classes can be exposed very easily. Rcpp modules are also described in more detail in their own vignette. Reference Classes R release 2.12.0 introduced Reference Classes. These are formal S4 classes with the corresponding dispatch method, but passed by reference and easy to use. Reference Classes can also be exposed to R by using Rcpp modules. Extension packackages The RcppArmadillo package permits use of the advanced C++ library 'Armadillo, a C++ linear algebra library aiming towards a good balance between speed and ease of use, providing integer, floating point and complex matrices and vectors with lapack / blas support via R. Armadillo uses templates for a delayed evaluation approach is employed (during compile time) to combine several operations into one and reduce (or eliminate) the need for temporaries. Armadillo is useful if C++ has been decided as the language of choice, rather than another language like Matlab or Octave, and aims to be as expressive as the former. Via Rcpp and RcppArmadillo, R users now have easy access to this functionality. Examples are provided in the RcppArmadillo package. The RcppGSL package permits easy use of the GNU Scientific Library (GSL), a collection of numerical routines for scientifc computing. It is particularly useful for C and C++ programs as it provides a standard C interface to a wide range of mathematical routines such as special functions, permutations, combinations, fast fourier transforms, eigensystems, random numbers, quadrature, random distributions, quasi-random sequences, Monte Carlo integration, N-tuples, differential equations, simulated annealing, numerical differentiation, interpolation, series acceleration, Chebyshev approximations, root-finding, discrete Hankel transforms physical constants, basis splines and wavelets. There are over 1000 functions in total with an extensive test suite. The RcppGSL package provides an easy-to-use interface between GSL data structures and R using concepts from Rcpp. The RcppGSL package also contains a vignette with more documentation. Legacy 'classic' API Packages still using code interfacing the initial 'classic' Rcpp API are encouraged to migrate to the new API. Should a code transition not be possible, backwards compatibility is provided by the RcppClassic package released alongside Rcpp 0.9.0. By including RcppClassic.h and building against the RcppClassic package and library, vintage code can remain operational using the classic API. The short vignette in the RcppClassic package has more details. Documentation The package contains a total of eight vignettes the first of which provides a short and succinct introduction to the Rcpp package along with several motivating examples. Links Support Questions about Rcpp should be directed to the Rcpp-devel mailing list https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Dirk Eddelbuettel, Romain Francois, Doug Bates and John Chambers
December 2010

22 December 2010

Dirk Eddelbuettel: RcppExamples 0.1.2

A new version of our RcppExamples, package is now on CRAN. RcppExamples contains a few illustrations of how to use Rcpp. It grew out of documentation for the classic API (now in its own package RcppClassic) and we added more functions documenting how to do the same with the new API we have been focusing on for the last year or so. One of the things I added in the last few days was the example below showing how to use Rcpp::List with lookups to replace use of the old and deprecated RcppParams. It also show how to return values to R rather easily <quote>
#include <Rcpp.h>
RcppExport SEXP newRcppParamsExample(SEXP params)  
    try                                         // or use BEGIN_RCPP macro
        Rcpp::List rparam(params);              // Get parameters in params.
        std::string method   = Rcpp::as<std::string>(rparam["method"]);
        double tolerance     = Rcpp::as<double>(rparam["tolerance"]);
        int    maxIter       = Rcpp::as<int>(rparam["maxIter"]);
        Rcpp::Date startDate = Rcpp::Date(Rcpp::as<int>(rparam["startDate"])); // ctor from int
        
        Rprintf("\nIn C++, seeing the following value\n");
        Rprintf("Method argument    : %s\n", method.c_str());
        Rprintf("Tolerance argument : %f\n", tolerance);
        Rprintf("MaxIter argument   : %d\n", maxIter);
        Rprintf("Start date argument: %04d-%02d-%02d\n", 
                startDate.getYear(), startDate.getMonth(), startDate.getDay());
        return Rcpp::List::create(Rcpp::Named("method", method),
                                  Rcpp::Named("tolerance", tolerance),
                                  Rcpp::Named("maxIter", maxIter),
                                  Rcpp::Named("startDate", startDate),
                                  Rcpp::Named("params", params));  // or use rparam
      catch( std::exception &ex )               // or use END_RCPP macro
        forward_exception_to_r( ex );
      catch(...)   
        ::Rf_error( "c++ exception (unknown reason)" ); 
     
    return R_NilValue; // -Wall
 
</quote> The package is work-in-progress and needs way more general usage examples for Rcpp and particularly the new API. But it's a start. A few more details on the page are on the RcppExamples page.

20 December 2010

Dirk Eddelbuettel: Rcpp 0.9.0 and RcppClassic 0.9.0

A new release 0.9.0 of Rcpp is now available at CRAN and has just been uploaded to Debian. As always, sources are also available from my local directory here. With this release, the older API which we have been referring to as the classic Rcpp API has been split off into its own new package RcppClassic to ensure backwards compatibility. Rcpp will now contain only the new API. We also fixes a number a minor bugs and applied a few contributed patches which extended functionality or documentation as detailed below in the NEWS entry:
0.9.0   2010-12-19
    o   The classic API was factored out into its own package RcppClassic which
        is released concurrently with this version.
    o   If an object is created but not initialized, attempting to use
        it now gives a more sensible error message (by forwarding an
        Rcpp::not_initialized exception to R).
    o   SubMatrix fixed, and Matrix types now have a nested ::Sub typedef.
  
    o   New unexported function SHLIB() to aid in creating a shared library on
        the command-line or in Makefile (similar to CxxFlags() / LdFlags()).
    o   Module gets a seven-argument ctor thanks to a patch from Tama Ma.
    o   The (still incomplete) QuickRef vignette has grown thanks to a patch
        by Christian Gunning.
    o   Added a sprintf template intended for logging and error messages.
    o   Date::getYear() corrected (where addition of 1900 was not called for); 
        corresponding change in constructor from three ints made as well.
    o   Date() and Datetime() constructors from string received a missing
        conversion to int and double following strptime. The default format
        string for the Datetime() strptime call was also corrected.
    o   A few minor fixes throughout, see ChangeLog.
Thanks to CRANberries, there is also a diff to the previous release 0.8.9. As always, even fuller details are on the Rcpp Changelog page and the Rcpp page which also leads to the downloads, the browseable doxygen docs and zip files of doxygen output for the standard formats. A local directory has source and documentation too. Questions, comments etc should go to the rcpp-devel mailing list off the R-Forge page

Next.

Previous.