The way we implemented as<mat>
requires that the R object you pass is a matrix. And in your example B
is a vector:
> A <- matrix( runif(25), ncol = 5)
> A
[,1] [,2] [,3] [,4] [,5]
[1,] 0.19215339 0.5857249 0.14345222 0.32154176 0.6162155
[2,] 0.95753898 0.9618379 0.06239842 0.06200197 0.7044018
[3,] 0.33575790 0.1372804 0.03027635 0.62662467 0.9778451
[4,] 0.16504957 0.1919765 0.49176372 0.94841456 0.2914772
[5,] 0.01570709 0.8055231 0.51218581 0.79562809 0.6939380
> B <- skewness( A )
> B
[1] 1.15196587 -0.04547576 0.32186257 -0.30788111 -0.29251009
For conversion to arma::vec
I don't reproduce the behavior you see. The arma::vec
has 3 elements:
require( RcppArmadillo ) ## and make sure you have Rcpp 0.10.0 or later
sourceCpp( code = '
// [[Rcpp::depends("RcppArmadillo")]]
#include <RcppArmadillo.h>
using namespace arma ;
using namespace Rcpp ;
// [[Rcpp::export]]
List foo( NumericVector x){
vec B = Rcpp::as<vec>(x);
return List::create(
_["nrows"] = B.n_rows,
_["ncols"] = B.n_cols
) ;
}
')
foo( c(1, 2, 3 ) )
# $nrows
# [1] 3
#
# $ncols
# [1] 1