[Rcpp-devel] What the rcpp function does ?

Christian Authmann authmanc at Mathematik.Uni-Marburg.de
Fri Aug 15 09:31:44 CEST 2014


On 15.08.2014 07:15, PO SU wrote:
 > Dear Rcppusers,
 > When i am learning Rcpp , i meet the following function, i can't
 > figure out its use, May you explain to me ?

It's similar to std::find_if(): it returns the index of the first 
element in a list that matches a given predicate.

For example, consider a function "odd", which returns TRUE for odd 
numbers, FALSE otherwise.
f4(odd, c(4,6,10,15,3,8)) would return 4, because the fourth number in 
the list (15) is the first odd number.


Remember that R will always work on vectors - if the predicate returns 
TRUE, that's actually a vector with a single value TRUE. Hence the 
LogicalVector and the check for res[0] instead of res.




-- 
Christian Authmann
Philipps-Universität Marburg
Fachbereich Mathematik und Informatik
AG Datenbanksysteme
Hans-Meerwein-Straße
D-35032 Marburg


More information about the Rcpp-devel mailing list