Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Speeding up roxygen

Tags:

r

roxygen

Running R CMD roxygen on a big package can take quite a long time. It's obviously inefficient as well as it goes through everything regardless of whether a file has changed since the last roxygen call.

Any tips on how to speed things up?

like image 609
Dr G Avatar asked Jan 20 '11 15:01

Dr G


1 Answers

Roxygen2 > 3.0.0 is substantially faster, and no longer needs caching.


In my local version of roxygen, I have:

library(memoize)
cached.parse.ref <- memoize(parse.ref)
cached.parse.srcfile <- memoize(parse.srcfile)

parse.file <- function(file) {
  srcfile <- srcfile(file)

  res <- try(cached.parse.srcfile(srcfile), silent = TRUE)
  if (inherits(res, "try-error")) {
    stop("Can't pass", file, "\n", res, call. = FALSE)
  }
  res
}

parse.srcfile <- function(srcfile) {
  srcrefs <- attributes(parse(srcfile$filename,
                              srcfile=srcfile))$srcref
  if (length(srcrefs) > 0)
    parse.refs(zip.list(prerefs(srcfile, srcrefs), srcrefs))
  else
    nil

}

I think those are the only changes you need, but I'm not sure. It speeds up roxygen by an order of magnitude.

like image 118
hadley Avatar answered Oct 25 '22 23:10

hadley