// !!! SEXP set_all_varnames_R(SEXP s, SEXP names) { // testDbg << "set_all_varnames_R"<<endl; AbstractMatrix * p = getAbstractMatrixFromSEXP(s); if (p == NULL) { error_R("pointer is NULL\n"); return R_NilValue; } // R_len_t nvars = (R_len_t) 0; unsigned long nvars = 0; try { nvars = p->getNumVariables(); } catch (int errcode) { error_R("can not p->getNumVariables()\n"); return R_NilValue; } // check that length of SEXP names is the same!!! for (unsigned long i = 0; i < nvars; i++) { string varname = CHAR(STRING_ELT(names,i)); try { p->writeVariableName(i,FixedChar(varname)); } catch (int errcode) { error_R("can not set variable name for variable %ul\n",i); return R_NilValue; } } SEXP ret; PROTECT(ret = allocVector(LGLSXP, 1)); LOGICAL(ret)[0] = TRUE; UNPROTECT(1); return ret; }
// !!! SEXP set_all_varnames_R(SEXP s, SEXP names) { CHECK_PTR(s); AbstractMatrix * p = (AbstractMatrix*) R_ExternalPtrAddr(s); if (p == NULL) { error_R("pointer is NULL\n"); return R_NilValue; } R_len_t nvars = (R_len_t) 0; try { nvars = p->getNumVariables(); } catch (int errcode) { error_R("can not p->getNumVariables()\n"); return R_NilValue; } // check that length of SEXP names is the same!!! for (unsigned long int i = 0; i < nvars; i++) { std::string varname = CHAR(STRING_ELT(names, i)); try { p->writeVariableName(i, fixedchar(varname)); } catch (int errcode) { error_R("can not set variable name for variable %ul\n", i); return R_NilValue; } } SEXP ret; PROTECT(ret = allocVector(LGLSXP, 1)); LOGICAL(ret)[0] = TRUE; UNPROTECT(1); return ret; }