I want to use the "glasso" package in Rcpp code, and the cpp code is as follow:
#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
using namespace Rcpp;
// [[Rcpp::export]]
List sec(arma::mat x,double lam){
Environment gla("package:glasso");
Function gl=gla["glasso"];
double thr=1e-2;bool approx=0;
bool diag=1; bool nu=0;
List bc(5);
bc=gl(x,lam,nu,thr,thr,approx,approx,nu,nu,diag);
return(bc);}
But When I source the code in R and I get follow error.
set.seed(100)
x<-matrix(rnorm(50*10),ncol=10)
s<- var(x)
library(glasso)
a<-sec(s, 0.01)
"Error in sec(s, 0.01) : Evaluation error: subscript out of bounds."
I check document of "glasso" package, the result list contain 5 values, so I'm confused where is the problem.