Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R package and execution time

I have developed a big library of functions in R. For the moment I just load ("source") the functions at the beginning of all my scripts.

I have seen that I can create packages.

My question is: Will that improve the execution time of my functions? (by transforming interpreter code into machine language?)

What does the package creation does? Does it creates binaries?

Thanks fred

like image 371
RockScience Avatar asked Jan 21 '11 11:01

RockScience


1 Answers

There isn't an R compiler yet Packaging your R code won't improve its execution time massively. It also won't create binaries for you - you need to build those from the package tarball (or get CRAN or similar to build them for you). There is now a byte compiler for R and R's packages are now by default byte compiled. Speed improvements are in general modest - don't expect C-like speed.

Packaging R code just does exactly that; it packages the R code, code to be compiled (C Fortran etc), man pages, documentation, tests etc into a standard format that can be distributed to users and installed/built on multiple architectures.

Packages can take advantage of things like lazy loading such that R objects (your functions say) are only loaded when needed, whereas source loads them all into the global environment (by default).

If you don't intend to distribute your code then there are few benefits of packaging just for your own use, but if you do package and write documentation and examples/tests, you might be alerted to changes in the package code that break examples or cause tests to fail. That way you are better informed as to the reliability of your code, even if it is only you using it!

like image 157
Gavin Simpson Avatar answered Sep 30 '22 12:09

Gavin Simpson