On 18 August 2011 at 08:44, Dirk Eddelbuettel wrote: | | On 18 August 2011 at 16:24, Darren Cook wrote: | | I'd like to shamelessly hijack Christopher Wray's question to ask if | | there is a convention for parameter naming with Rcpp and inline. Well, | | actually I'll propose one, to then see what others prefer. | | | | First I would propose to use long variable names, instead of | | abbreviations, in both the CPP and R sides [1]. I already know enough R | | to know this will be immediately rejected ;-) [2] | | | | Anyway, while trying to understand the posted code I found myself | | jumping back and forth between the below two blocks of code, muttering | | to myself, "so the bottleneck is proportional to 2nd parameter which is | | SamSize, which is then called SS_C, ..." | | | | > src<-' | | > NumericVector RetIn(RetVec); | | > int SS_C=as<int>(SamSize); | | > double St_C=as<double>(StM); | | > int ES_C=as<int>(ExpSize); | | > ... | | > sscpp2<-cfunction( | | > signature(RetVec="numericVector",SamSize="numeric",StM="numeric",ExpSize="numeric"), | | > src,inc, Rcpp=TRUE,cppargs="",convention=".Call") | | | | So, my proposal would be to use the same names in the signature that you | | intend to use in the C++ code, but with underline appended. I.e. | | You must do that anyway or you get linking errors.
I was sloppy: compile-time errors. I.e. this: errorDemo <- cxxfunction(signature(badName="integer"), plugin='Rcpp', body=' Rcpp::IntegerVector x(otherName); return 2*x; ') gives you Error in compileCode(f, code, language = language, verbose = verbose) : Compilation ERROR, function(s)/method(s) not created! file181a5f5c.cpp: In function ‘SEXPREC* file181a5f5c(SEXPREC*)’: file181a5f5c.cpp:32:26: error: ‘otherName’ was not declared in this scope file181a5f5c.cpp:33:13: error: cannot convert ‘Rcpp::sugar::Times_Vector_Primitive<13, true, Rcpp::Vector<13> >’ to ‘SEXPREC*’ in return make: *** [file181a5f5c.o] Error 1 In addition: Warning message: running command '/usr/lib64/R/bin/R CMD SHLIB file181a5f5c.cpp 2> file181a5f5c.cpp.err.txt' had status 1 R> So as I indicated, you have no choice but to make those match. Dirk | The rest is stylistic, and we do not impose a style (besides maybe the | default indentation I get from Emacs :). If you need a style, I suggest to | follow R conventions as layed out in the R Internals manual. Personally, I | also like this one: | | http://quantlib.org/style.shtml | | Descriptive names are good, comments are good, using separate names for | members vars is good and I still mostly prepend m_. | | Dirk | | | | signature(RetIn_="numericVector",SS_C_="numeric",St_C_="numeric",ES_C_="numeric") | | | | The C++ code then starts: | | NumericVector RetIn(RetIn_); | | int SS_C=as<int>(SS_C_); | | double St_C=as<double>(St_C_); | | int ES_C=as<int>(ES_C); | | | | What conventions are other people using? | | | | Darren | | | | [1]: I am not alone in this. E.g. see "Rename Method" in Martin Fowler's | | Refactoring; "It's All Writing" in The Pragmatic Programmer (ch.8); etc. | | | | [2]: I realize many R functions are direct translations of mathematical | | functions, so calling a parameter "p" is not as meaningless as it | | appears at first glance. I still think it should be "probabilities" not | | "p" (yes, "qunif", I'm looking at you), but I realize I'm in a minority | | when surrounded byq mathematicians. | | | | | | | | | | -- | | Darren Cook, Software Researcher/Developer | | | | http://dcook.org/work/ (About me and my work) | | http://dcook.org/blogs.html (My blogs and articles) | | _______________________________________________ | | Rcpp-devel mailing list | | Rcpp-devel@lists.r-forge.r-project.org | | https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel | | -- | Two new Rcpp master classes for R and C++ integration scheduled for | New York (Sep 24) and San Francisco (Oct 8), more details are at | http://dirk.eddelbuettel.com/blog/2011/08/04#rcpp_classes_2011-09_and_2011-10 | http://www.revolutionanalytics.com/products/training/public/rcpp-master-class.php | _______________________________________________ | Rcpp-devel mailing list | Rcpp-devel@lists.r-forge.r-project.org | https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel -- Two new Rcpp master classes for R and C++ integration scheduled for New York (Sep 24) and San Francisco (Oct 8), more details are at http://dirk.eddelbuettel.com/blog/2011/08/04#rcpp_classes_2011-09_and_2011-10 http://www.revolutionanalytics.com/products/training/public/rcpp-master-class.php _______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel