C/C++ function registration mechanism
1
0
Entering edit mode
@holger-frohlich-1963
Last seen 10.2 years ago
-----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-----
• 1.5k views
ADD COMMENT
0
Entering edit mode
Oleg Sklyar ▴ 260
@oleg-sklyar-1882
Last seen 10.2 years ago
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
ADD COMMENT

Login before adding your answer.

Traffic: 472 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6