Dominick Samperi
2010-Apr-27 20:16 UTC
[Rd] Resolving functions using R's namespace mechanism can double runtime
It appears that the runtime for an R script can more than double if a few references to a function foo() are replaced by more explict references of the form pkgname::foo(). The more explicit references are of course required when two loaded packages define the same function. I can understand why use of this mechanism is not free in an interpreted environment like R, but the cost seems rather high. Dominick [[alternative HTML version deleted]]
Seth Falcon
2010-Apr-27 20:33 UTC
[Rd] Resolving functions using R's namespace mechanism can double runtime
On 4/27/10 1:16 PM, Dominick Samperi wrote:> It appears that the runtime for an R script can more than double if a few > references to a function foo() are replaced by more explict references > of the form pkgname::foo(). > > The more explicit references are of course required when two > loaded packages define the same function. > > I can understand why use of this mechanism is not free in an > interpreted environment like R, but the cost seems rather high.`::` is a function, so there is going to be overhead. OTOH, there is no reason to pay for the lookup more than once. For example at startup, you could do: myfoo <- pkgname::foo And then later call myfoo() and I don't think you will see the added cost. You can formalize the above approach in package code by renaming function in the importFrom directive where I believe you can do: importFrom(pkgname, myfoo=foo) + seth -- Seth Falcon | @sfalcon | http://userprimary.net/
Romain Francois
2010-Apr-27 20:38 UTC
[Rd] Resolving functions using R's namespace mechanism can double runtime
Le 27/04/10 22:16, Dominick Samperi a ?crit :> It appears that the runtime for an R script can more than double if a few > references to a function foo() are replaced by more explict references > of the form pkgname::foo().It would probably help your question if you provide some benchmarks. a::b is just a shortcut for `::`( a, b ).> The more explicit references are of course required when two > loaded packages define the same function.Not really. You can : - resolve once: my_foo <- pkgname::foo - import the variable into your namespace using the importFrom namespace directive.> I can understand why use of this mechanism is not free in an > interpreted environment like R, but the cost seems rather high. > > Dominick-- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/9aKDM9 : embed images in Rd documents |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7