Skip to content

Instantly share code, notes, and snippets.

#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
StringVector check( StringVector x ) {
Rcout << "The type of x is: " << ::TYPEOF( x ) << std::endl;
Rcout << "The type of x(0) is: " << ::TYPEOF( x(0) ) << std::endl;
Rcout << "The integer associated with STRSXPs is: " << STRSXP << std::endl;
Rcout << "The integer associated with CHARSXPs is: " << CHARSXP << std::endl;
Rcout << "Is x a string?: " << ::Rf_isString(x) << std::endl;
---
title: Using Boost's foreach macro
author: Kevin Ushey
license: GPL (>= 2)
tags: basics boost
summary: Boost's BOOST_FOREACH can enable a more functional programming style.
---
Boost provides a macro, `BOOST_FOREACH`, that allows us to easily iterate
over elements in a container, similar to what we might
@kevinushey
kevinushey / RcppApply.Rmd
Last active November 10, 2022 00:18
Make your own 'apply' functions for matrices
---
title: Make your own 'apply' functions for matrices
author: Kevin Ushey
license: GPL (>= 2)
tags: Rcpp apply matrix
summary: Clever use of sourceCpp can allow you to define your own 'apply' functions on the fly.
---
Make your own 'apply' functions
==========
@kevinushey
kevinushey / apply_mean.cpp
Last active April 14, 2019 06:23
row, column-wise operations in Rcpp
// the column-wise implementation is just as fast as colMeans,
// but the row-wise operation is not quite as fast as rowMeans.
// can I do better?
#include <Rcpp.h>
using namespace Rcpp;
template <class T>
inline double do_mean( T& x ) {
@kevinushey
kevinushey / strings_with_rcpp.Rmd
Last active December 10, 2015 20:28
Handling Strings with Rcpp
---
title: Handling Strings with Rcpp
author: Kevin Ushey
license: GPL (>= 2)
tags: string vector
summary: Demonstrates how one might handle a vector of strings with `Rcpp`,
in addition to returning output.
---
This is a quick example of how you might use Rcpp to send and receive R