Ramon Diaz <[EMAIL PROTECTED]> writes: > Dear all, > > I have a piece of code, call it "FA", that will be called thousands of times > in a typical run of function "FB". I can: > > a) define FA as a function outside of FB (in the global environment), and call > it; > b) define FA as a function inside the body of FB and call it; > c) "expand inline" FA inside FB. > > FA mainly does data frame subsetting, runs svd's, and calls compiled C++ code. > > I think I recall reading something about differences in efficiency between > those three approaches, but I can't find the information (I've searched the > email archives, Venables & Ripley's "S programming" and MASS, the R manuals, > and Burn's "S Poetry"). > > Are there any real performance differences? > > (I'd personally prefer b) since these functions will hopefully become a > contributed package, and FA is not supposed to be used directly by an end > user. I am aware of scoping differences between the three approaches, but > that is not my main concern now).
After R-1.7.0 is released you can use a namespace to make FA local to your package. As Luke Tierney said in his presentation at DSC-2003, people have in the past written functions in the style of b) primarily to keep the names of local utility functions hidden. Style a) and the use of namespaces is a better way of accomplishing this. I agree with what Barry Rowlingson wrote in his reply. The best approach is to write the code in the most convenient and understandable way then profile the execution of the code to see where the bottlenecks really are. ______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
