Vladimir Eremeev
2007-Jan-23 11:12 UTC
[Rd] is it necessary to always register C routines with R_registerRoutines?
I am writing bindings to the neural network simulator SNNS. At present I have used only .C interface, now I'm studying .Call interface. I have adapted the example from page 77 of r-exts.pdf, however, it crashes R. I use MingW as recommended by Duncan Murdoch. Please, tell me what I am missing. The code is below. Thank you. SEXP snns_getVersion(void) {SEXP version; char *v; PROTECT(version=NEW_CHARACTER(15)); v=CHARACTER_POINTER(version); strcpy(v,krui_getVersion()); UNPROTECT(1); return version; }> sessionInfo()R version 2.4.1 (2006-12-18) i386-pc-mingw32 locale: LC_COLLATE=Russian_Russia.1251;LC_CTYPE=Russian_Russia.1251;LC_MONETARY=Russian_Russia.1251;LC_NUMERIC=C;LC_TIME=Russian_Russia.1251 attached base packages: [1] "stats" "graphics" "grDevices" "utils" "datasets" "methods" [7] "base" -- View this message in context: http://www.nabble.com/is-it-necessary-to-always-register-C-routines-with-R_registerRoutines--tf3063486.html#a8519680 Sent from the R devel mailing list archive at Nabble.com.
Vladimir Eremeev
2007-Jan-23 11:57 UTC
[Rd] is it necessary to always register C routines with R_registerRoutines?
sorry, forgot to mention. krui_getVersion returns char * SEXP snns_getVersion(void) {SEXP version; char *v; PROTECT(version=NEW_CHARACTER(15)); v=CHARACTER_POINTER(version); strcpy(v,krui_getVersion()); UNPROTECT(1); return version; } -- View this message in context: http://www.nabble.com/is-it-necessary-to-always-register-C-routines-with-R_registerRoutines--tf3063486.html#a8520292 Sent from the R devel mailing list archive at Nabble.com.
Brian Ripley
2007-Jan-24 09:15 UTC
[Rd] is it necessary to always register C routines with R_registerRoutines?
No, in answer to the subject line. On Tue, 23 Jan 2007, Vladimir Eremeev wrote:> I am writing bindings to the neural network simulator SNNS. > At present I have used only .C interface, now I'm studying .Call interface. > > I have adapted the example from page 77 of r-exts.pdf, however, it crashes > R.Page numbers depend on what paper it is formatted for, but on A4 this is nothing like the example on page 77.> I use MingW as recommended by Duncan Murdoch. > Please, tell me what I am missing. > The code is below. > > Thank you. > > SEXP snns_getVersion(void) > {SEXP version; > char *v; > > PROTECT(version=NEW_CHARACTER(15)); > v=CHARACTER_POINTER(version); > strcpy(v,krui_getVersion());I very much doubt that does what you think it does (but you have not told us). I think the S-compatible Rdefines.h macros are really confusing for use in R, as R and S differ in how character vectors are stored. In particular, use of CHARACTER_POINTER is likely to get into trouble as it is necessary to use SET_STRING_ELT in R. (Similarly, CREATE_STRING_VECTOR does no such thing: it creates an element of a character vector.) In this case version = mkString(krui_getVersion()); would seem to be all that is needed. But if you want to do it by hand, PROTECT(version=NEW_CHARACTER(1)); SET_STRING_ELT(version, 0, mkChar(krui_getVersion())); UNPROTECT(1); is the sort of thing needed.> UNPROTECT(1); > return version; > } > >> sessionInfo() > R version 2.4.1 (2006-12-18) > i386-pc-mingw32 > > locale: > LC_COLLATE=Russian_Russia.1251;LC_CTYPE=Russian_Russia.1251;LC_MONETARY=Russian_Russia.1251;LC_NUMERIC=C;LC_TIME=Russian_Russia.1251 > > attached base packages: > [1] "stats" "graphics" "grDevices" "utils" "datasets" "methods" > [7] "base" > > >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Apparently Analagous Threads
- Getting htmlParse to work with Hebrew? (on windows)
- Problem with accessing internal variable in package.
- About "=" in command line in windows.
- mboost_1.1-3 blackboost_fit (PR#13972)
- [bug report] Cyrillic letter "я" interrupts script execution via R source function