SEXP setMVElement(SEXP Sextptr, SEXP Sindex, SEXP Svalue){ if(!isInteger(Sindex)) { PRINTF("Error: Sindex is not an integer!\n"); return(returnStatus(false) ) ; } if(!R_ExternalPtrAddr(Sextptr)) { PRINTF("Error: Sextptr is not a valid external pointer\n"); return(returnStatus(false) ) ; } int index = INTEGER(Sindex)[0]; if(index < 1){ PRINTF("Error: index < 1\n"); return(returnStatus(false) ) ; } NimVecType *typePtr = static_cast< NimVecType* >(R_ExternalPtrAddr(Sextptr)); nimType vecType = (*typePtr).getNimType(); int nrowCpp = typePtr->size(); if(index > nrowCpp){ PRINTF("Error: index too large\n"); return(returnStatus(false) ) ; } cSetMVElementSingle( typePtr, vecType, index, Svalue ); SEXP SEXP_2_int(SEXP rPtr, SEXP refNum, SEXP rScalar); return(returnStatus(true) ); }
SEXP setGraph(SEXP SedgesFrom, SEXP SedgesTo, SEXP SedgesFrom2ParentExprIDs, SEXP Stypes, SEXP Snames, SEXP SnumNodes) { vector<int> edgesFrom = SEXP_2_vectorInt(SedgesFrom, -1); // -1 subtracted here vector<int> edgesTo = SEXP_2_vectorInt(SedgesTo, -1); // -1 substracted here vector<int> edgesFrom2ParentExprIDs = SEXP_2_vectorInt(SedgesFrom2ParentExprIDs); vector<NODETYPE> types; SEXP_2_nodeType(Stypes, types); vector<string> names; STRSEXP_2_vectorString(Snames, names); int numNodes = SEXP_2_int(SnumNodes); nimbleGraph *newGraph = new nimbleGraph; newGraph->setNodes(edgesFrom, edgesTo, edgesFrom2ParentExprIDs, types, names, numNodes); SEXP SextPtrAns; PROTECT(SextPtrAns = R_MakeExternalPtr(newGraph, R_NilValue, R_NilValue)); R_RegisterCFinalizerEx(SextPtrAns, &nimbleGraphFinalizer, TRUE); UNPROTECT(1); return(SextPtrAns); };
SEXP C_getDependencyPathCountOneNode(SEXP SgraphExtPtr, SEXP Snode) { nimbleGraph *graphPtr = static_cast<nimbleGraph *>(R_ExternalPtrAddr(SgraphExtPtr)); int node = SEXP_2_int(Snode, 0, -1); // subtract 1 index for C int result = graphPtr->getDependencyPathCountOneNode(node); return(int_2_SEXP(result)); }