Take the 2-minute tour ×  The recent questions regarding the use
of require versus :: raised the question about which programming
styles are used when programming in R, and what their
advantages/disadvantages are. Browsing through the source code
or browsing on the net, you see a lot of different styles
displayed.  The main trends in my code :    • I play a lot with
the indices (and nested indices), which results in rather
obscure code sometimes but is generally a lot faster than other
solutions. eg: x[x < 5] <- 0 instead of x <- ifelse(x < 5, x, 0)
• I tend to nest functions to avoid overloading the memory with
temporary objects that I need to clean up. Especially with
functions manipulating large datasets this can be a real burden.
eg : y <- cbind(x,as.numeric(factor(x))) instead of y <-
as.numeric(factor(x)) ; z <- cbind(x,y)    • I write a lot of
custom functions, even if I use the code only once in eg. an
sapply. I believe it keeps it more readible without creating
objects that can remain lying around