Blog Archives

Using Rcout for output synchronised with R

January 8, 2013
By

The Writing R Extensions manual, which provides the gold standard of documentation as far as extending R goes, suggests to use Rprintf and REprintf for output (from C/C++ code) as these are matched to the usual output and error streams maintained by R ...

Read more »

Using the Rcpp sugar function clamp

January 7, 2013
By

Since the 0.10.* release series, Rcpp contains a new sugar function clamp which can be used to limit vectors to both a minimum and maximim value. This recent StackOverflow question permitted clamp to shine. We retake some of the answers, including the ...

Read more »

Using the Rcpp Timer

January 6, 2013
By

Sine the 0.10.2 release, Rcpp contains an internal class Timer which can be used for fine-grained benchmarking. Romain motivated Timer in a post to the mailing * list where Timer is used to measure the different components of the costs of random number...

Read more »

Performance Benchmark of Running Sum Functions

January 6, 2013
By

First, let us consider a running sum function in pure R. To get started, I looked at the source code of the TTR package to see the algorithm used in runSum. The runSum function uses a Fortran routine to compute the running/rolling sum of a vector. The ...

Read more »

Calling R Functions from C++

January 5, 2013
By

At its very essence, Rcpp permits easy access to native R objects at the C++ level. R objects can be simple vectors, list or matrices; compound data structures created from these; objects of S3, S4 or Reference Class vintage; or language objects a...

Read more »

Armadillo eigenvalues

January 4, 2013
By

Today a (slightly confused) question on StackOverflow wondered how to access R’s facilities for eigenvalues calculations from C code. For this, we need to step back and consider how this is done. In fact, R farms the calculation out to the BLAS....

Read more »

Accessing environments

January 3, 2013
By

Extending R with C++ code by using Rcpp typically involves function calls by leveraging the existing .Call() interface of the R API. Passing values back and forth is then done in manner similar to programming with functions. However, on occassion it i...

Read more »

Armadillo subsetting

January 2, 2013
By

A StackOverflow question asked how convert from arma::umat to arma::mat. The former is format used for find and other logical indexing. For the particular example at hand, a call to the conv_to converter provided the solution. We rewrite the answer he...

Read more »

STL for_each and generalized iteration

January 1, 2013
By

The STL contains a very general looping or sweeping construct in the for_each algorith. It can be used with function objects (such as the simple square function used here) but also with custom class which can be used to keep to keep state. #include <...

Read more »

Sugar Functions head and tail

January 1, 2013
By

The R functions head and tail return the first (last) n elements of the input vector. With Rcpp sugar, the functions head and tail work the same way as they do in R. Here we use std::sort from the STL and then tail to return the top n items (items wit...

Read more »

Sponsors

Mango solutions



RStudio homepage



Zero Inflated Models and Generalized Linear Mixed Models with R

Quantide: statistical consulting and training

datasociety

http://www.eoda.de





ODSC

ODSC

CRC R books series





Six Sigma Online Training









Contact us if you wish to help support R-bloggers, and place your banner here.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)