Rcpp - Returning a pre-calculated hardcoded matrix with more than 20 elements

I am working on a function, which needs to return a 20x20 pre-calculated matrix of floating point numbers.

My code snippet below runs as long as I only enter maximum 20 elements, on the 21st element it fails with no matching function for call to 'create'. So, how do I upscale to the full 20x20 matrix with hardcoded values?

#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
NumericVector get_pmat(){
  
  // Create vector
  NumericVector pmat = NumericVector::create(
    1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1, 8.1, 9.1, 10.1,
    11.1, 12.1, 13.1, 14.1, 15.1, 16.1, 17.1, 18.1, 19.1, 20.1);
  
  // Create a matrix, by setting vector dimensions
  pmat.attr("dim") = Dimension(5, 4);
  
  // Return
  return pmat;
}

// Run test
/*** R
get_pmat()
*/

Haven't run this, but by eye, it appears that it runs out of dimension.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.