The Art of R Programming

(WallPaper) #1

14


PERFORMANCE ENHANCEMENT: SPEED AND MEMORY


In computer science curricula, a common
theme is the trade-off between time and
space. In order to have a fast-running pro-
gram, you may need to use more memory space.

On the other hand, in order to conserve memory space,


you might need to settle for slower code. In the R lan-


guage, this trade-off is of particular interest for the fol-


lowing reasons:



  • R is an interpreted language. Many of the commands are written in C
    and thus do run in fast machine code. But other commands, and your
    own R code, are pure R and thus interpreted. So, there is a risk that
    your R application may run more slowly than you would like.

  • All objects in an R session are stored in memory. More precisely, all
    objects are stored in R’s memory address space. R places a limit of
    231 −1 bytes on the size of any object, even on 64-bit machines and
    even if you have a lot of RAM. Yet some applications do encounter
    larger objects.

Free download pdf