I want to calculate the derivative of the function f by Rcpp. I just found some resources in https://cran.r-project.org/web/packages/StanHeaders/vignettes/stanmath.html, which use stan headers and rcppEigen. Since all my program is coded by rcpparmadillio, I'm wondering how can I access to the auto-derivative functions by rcpparmadillio and stan header(May be other AD packages).
#include <RcppArmadillo.h>
// [[Rcpp::plugins("cpp11")]]
// [[Rcpp::depends(RcppArmadillo)]]
#include <RcppArmadilloExtensions/sample.h>
using namespace Rcpp;
using namespace arma;
using namespace std;
/* function */
// [[Rcpp::export]]
doule f(arma::rowvec x){
arma::mat yy=x.t()*x;
double res=arma::sun(x);
rerutn(res);
}