[Rcpp-devel] Parameter Naming (was: Speed gain assistance)

Darren Cook darren at dcook.org
Thu Aug 18 09:24:48 CEST 2011


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.

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)


More information about the Rcpp-devel mailing list