[BioC] C/C++ function registration mechanism

Oleg Sklyar osklyar at ebi.ac.uk
Wed Dec 6 10:44:07 CET 2006


Hi,

Using .Call technique this is done as follows and I would strongly 
recommend to use .Call to prevent crashing on wrong data types:

SEXP OAWrapper (SEXP _Rpre, SEXP _m, SEXP _n, SEXP _mod, SEXP _res) {
	double * Rpre;
	int * m;

	Rpre = REAL(_Rpre);
	m = INTEGER(_m);
etc etc etc
	/* you MUST return at least this or a new variable, this
	 function MUST NOT be void as R expects a return from every
	function */

	return R_NilValue;
}

Then you can register it as follows:

static R_CallMethodDef cMethods[] = {
	{"OAWrapper", (DL_FUNC) &OAWrapper, 5},
	{NULL, NULL, 0}
}

void R_init_GOSim(DllInfo *info){
	/* you also had order of parameter here */
	R_registerRoutines(info, NULL, cMethods, NULL, NULL);
}

This way I do my functions and they work perfectly fine :)

Best
Oleg


Holger Fröhlich wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hi all,
> 
> has anybody experience with the registration mechanism for C/C++
> functions for R?
> 
> I have a C function of the form:
> 
> void OAWrapper(double* Rpre, int* m, int* n, int *mod, double *res)
> 
> which I want to register.
> However, when I write
> 
> void R_init_GOSim(DllInfo *info){
> 	R_CMethodDef cMethods[] = {{"OAWrapper", &OAWrapper, 5,
> {REALSXP,INTSXP, INTSXP, INTSXP, REALSXP}}, {NULL, NULL, 0}};
> 	R_registerRoutines(info, cMethods, NULL, NULL, NULL);
> }
> 
> then R crashes. Has anybody an idea?
> 
> Thank you very much
> 
> Holger
> 
> 
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.2.2 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> 
> iD8DBQFFdoy75ZMgwjLrZIMRAu4SAJ9uyUFdMu5Ouk2Zie+696yRXmjyQACgqUcp
> yodS/0OaMiF7CQnxM0EWLUE=
> =YK6U
> -----END PGP SIGNATURE-----
> 
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor

-- 
Dr Oleg Sklyar * EBI/EMBL, Cambridge CB10 1SD, England * +44-1223-494466



More information about the Bioconductor mailing list