6 typedef Rboolean (*RObjectTester)(SEXP);
8 void RObjectTestExpectedType(SEXP x, RObjectTester expectedtype,
const char *nam);
9 Rboolean isValidSparseMatrix(SEXP x);
10 Rboolean isNumericScalar(SEXP x);
12 void RObjectTestExpectedType(SEXP x, RObjectTester expectedtype,
const char *nam){
13 if(expectedtype != NULL){
16 Rf_warning(
"Expected object. Got NULL.");
18 if(Rf_isNumeric(x) && !Rf_isReal(x)) {
19 Rf_warning(
"NOTE: 'storage.mode(%s)' must be 'double' when attribute 'check.passed' is set for 'data'.",nam);
21 Rf_error(
"Error when reading the variable: '%s'. Please check data and parameters.",nam);
25 Rboolean isValidSparseMatrix(SEXP x){
26 if(!Rf_inherits(x,
"dgTMatrix"))Rf_warning(
"Expected sparse matrix of class 'dgTMatrix'.");
27 return Rf_inherits(x,
"dgTMatrix");
29 Rboolean isNumericScalar(SEXP x){
31 Rf_warning(
"Expected scalar. Got length=%i",LENGTH(x));
40 SEXP getListElement(SEXP list,
const char *str, RObjectTester expectedtype=NULL);
41 int getListInteger(SEXP list,
const char *str,
int default_value = 0);
43 SEXP getListElement(SEXP list,
const char *str, RObjectTester expectedtype=NULL)
45 if(config.debug.getListElement)std::cout <<
"getListElement: " << str <<
" ";
46 SEXP elmt = R_NilValue, names = Rf_getAttrib(list, R_NamesSymbol);
48 for (i = 0; i < Rf_length(list); i++)
49 if(strcmp(CHAR(STRING_ELT(names, i)), str) == 0)
51 elmt = VECTOR_ELT(list, i);
54 if(config.debug.getListElement)std::cout <<
"Length: " << LENGTH(elmt) <<
" ";
55 if(config.debug.getListElement)std::cout <<
"\n";
56 RObjectTestExpectedType(elmt, expectedtype, str);
59 int getListInteger(SEXP list,
const char *str,
int default_value = 0) {
60 SEXP tmp = getListElement(list, str);
61 if ( tmp == R_NilValue ) {
62 Rf_warning(
"Missing integer variable '%s'. Using default: %d. (Perhaps you are using a model object created with an old TMB version?)", str, default_value);
65 return INTEGER(tmp)[0];