Example #1
0
	SEXP set_all_obsnames_R(SEXP s, SEXP names) {
		//testDbg << "set_all_obsnames_R"<<endl;
		AbstractMatrix * p = getAbstractMatrixFromSEXP(s);

		if (p == NULL) {
			error_R("pointer is NULL\n");
			return R_NilValue;
		}

		//R_len_t nobss = (R_len_t) 0;
		unsigned long int nobss = 0;

		try {
			nobss = p->getNumObservations();
		} catch (int errcode) {
			error_R("can not p->getNumObservations()\n");
			return R_NilValue;
		}

		// check that length of SEXP names is the same!!!

		for (unsigned long i = 0; i < nobss; i++) {
			string obsname = CHAR(STRING_ELT(names,i));
			try {
				p->writeObservationName(i,FixedChar(obsname));
			} catch (int errcode) {
				error_R("can not set observation name for observation %ul\n",i);
				return R_NilValue;
			}
		}

		SEXP ret;
		PROTECT(ret = allocVector(LGLSXP, 1));
		LOGICAL(ret)[0] = TRUE;
		UNPROTECT(1);
		return ret;

	}
Example #2
0
// !!!
SEXP set_all_obsnames_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 nobss = (R_len_t) 0;

	try {
		nobss = p->getNumObservations();
	} catch (int errcode) {
		error_R("can not p->getNumObservations()\n");
		return R_NilValue;
	}

	// check that length of SEXP names is the same!!!

	for (unsigned long int i = 0; i < nobss; i++) {
		std::string obsname = CHAR(STRING_ELT(names, i));
		try {
			p->writeObservationName(i, fixedchar(obsname));
		} catch (int errcode) {
			error_R("can not set observation name for observation %ul\n", i);
			return R_NilValue;
		}
	}

	SEXP ret;
	PROTECT(ret = allocVector(LGLSXP, 1));
	LOGICAL(ret)[0] = TRUE;
	UNPROTECT(1);
	return ret;

}