Skip to content
Prev 10634 / 10988 Next

[Rcpp-devel] Rcpp equivalent of sapply(L, length)

What about using "Rf_length"?

-------------------------------------------------------
#include <Rcpp.h>

using namespace Rcpp;

// [[Rcpp::export]]
IntegerVector c_listlengths(List L) {
    IntegerVector lens(L.size());

    for (int i=0; i<L.size(); i++) {
        SEXP x = L[i];
        lens(i) = Rf_length(x);
    }
    return lens;
}
----------------------------------------------------------

In R:
[1] 3 2 6
[1] 3 2 6
[1] 6 2 3


On Thu, Jul 1, 2021 at 5:14 PM Dr Gregory Jefferis <
jefferis at mrc-lmb.cam.ac.uk> wrote: