From the TMB tutorial, one defines objective functions in a .cpp
file, such that parameter names and names of model data structures are shared between the C++ function and what is called from R. For example, the tutorial.cpp
file:
#include <TMB.hpp> // Links in the TMB libraries
template<class Type>
Type objective_function<Type>::operator() ()
{
DATA_VECTOR(x); // Data vector transmitted from R
PARAMETER(mu); // Parameter value transmitted from R
PARAMETER(sigma); //
Type f; // Declare the "objective function" (neg. log. likelihood)
f = -sum(dnorm(x,mu,sigma,true)); // Use R-style call to normal density
return f;
}
After compilation and dyn.load
one can call this function from R, however, you need to know that the data vector is named x
, and that there are two parameter values mu
and sigma
. Is it possible to retrieve the names of these required objects some how from R?