Publications by Henrik Bengtsson
Set package repositories at startup
The below code shows how to configure the ‘repos’ option in R such that install.packages() etc will locate the packages without having to explicitly specify the repository. Just add it to the .Rprofile file in your home directory (iff missing, create it). For more details, see help(“Startup”).local({ repos <- getOption(...
696 sym R (527 sym/1 pcs)
Force R help HTML server to always use the same URL port
The below code shows how to configure the ‘help.ports’ option in R such that the built-in R help server always uses the same URL port. Just add it to the .Rprofile file in your home directory (iff missing, create it). For more details, see help(“Startup”).# Force the URL of the help to http://127.0.0.1:21510 options(help.ports=21510); A...
1385 sym R (420 sym/4 pcs)
Speed trick: unlist(…, use.names=FALSE) is heaps faster!
Sometimes a minor change to your R code can make a big difference in processing time. Here is an example showing that if you’re don’t care about the names attribute when unlist():ing a list, specifying argument use.names=FALSE can speed up the processing lots!> x <- split(sample(1000, size=1e6, rep=TRUE), rep(1:1e5, times=10)) > ...
785 sym R (248 sym/1 pcs)
This day in history (1997-04-01)
Today it’s 16 years ago and 367,496 messages later since Martin Mächler started the R-help (321,119 msgs), R-devel (45,830 msgs) and R-announce (547 msgs) mailing lists [1] – a great benefit to all of us. Special thanks to Martin and also thanks to everyone else contributing to these forums.[1] https://stat.ethz.ch/pipermail/r-help/1997-Ap...
745 sym 2 img
Speed trick: Assigning large object NULL is much faster than using rm()!
When processing large data sets in R you often also end up creating large temporary objects. In order to keep the memory footprint small, it is always good to remove those temporary objects as soon as possible. When done, removed objects will be deallocated from memory (RAM) the next time the garbage collection runs. Better: Use rm(list="x") in...
1978 sym R (459 sym/2 pcs)
PERFORMANCE: captureOutput() is much faster than capture.output()
The R function capture.output() can be used to “collect” the output of functions such as cat() and print() to strings. For example, > s <- capture.output({ + cat("Hello\nworld!\n") + print(pi) + }) > s [1] "Hello" "world!" "[1] 3.141593" More precisely, it captures all output sent to the standard output and returns a ch...
3360 sym R (2055 sym/8 pcs) 2 img 1 tbl
PITFALL: Did you really mean to use matrix(nrow, ncol)?
Are you a good R citizen and preallocates your matrices? If you are allocating a numeric matrix in one of the following two ways, then you are doing it the wrong way!x <- matrix(nrow=500, ncol=100) orx <- matrix(NA, nrow=500, ncol=100) Why? Because it is counter productive. And why is that? In the above, 'x' becomes a logical matr...
2645 sym R (1780 sym/12 pcs) 2 img
Milestone: 6000 packages on CRAN
Another 1000 packages were added to CRAN and this time in less than 12 months. Today (2014-10-29) on The Comprehensive R Archive Network (CRAN) package page: “Currently, the CRAN package repository features 6000 available packages.” Going from 5000 to 6000 packages took 355 days – which means that it on average was only ~8.5 h...
1510 sym 1 img
PACKAGE: matrixStats 0.13.1 – Methods that Apply to Rows and Columns of a Matrix (and Vectors)
A new release 0.13.1 of matrixStats is now on CRAN. The source code is available on GitHub. What does it do? The matrixStats package provides highly optimized functions for computing common summaries over rows and columns of matrices, e.g. rowQuantiles(). There are also functions that operate on vectors, e.g. logSumExp(). Their implementations...
3999 sym R (432 sym/1 pcs) 2 img
HOW TO: Package vignettes in plain LaTeX
Ever wanted to include a plain-LaTeX vignette in your package and have it compiled into a PDF? The R.rsp package provides a four-line solution for this. But, first, what's R.rsp? R.rsp is an R package that implements a compiler for the RSP markup language. RSP can be used to embed dynamic R code in any text-based source document to be compiled...
3751 sym 2 img 1 tbl