Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot call roxygenize function from Rscript batch file

I am writing a script that uses roxygen2 to automatically roxygenize my package. I'd like it to be executable so that it can be part of a larger script to prepare and install the package, but I cannot make it work with Rscript for some reason.

Here is the code:

#!/usr/bin/env Rscript
library(roxygen2)
roxygenize('.', copy=FALSE)

This works correctly if I start an interactive R session or if I submit the code using R CMD BATCH. However, I get this output and error if I run the script directly as an executable via Rscript (and I get the error regardless of whether the script is in the current directory or bin).

bin/roxygenize.R 
Loading required package: digest
Warning message:
package 'roxygen2' was built under R version 2.13.2 
Error in parse.files(r_files) : could not find function "setPackageName"
Calls: roxygenize -> parse.files
Execution halted

It looks like setPackageName is in base R, so I can't figure out why it's not there. Additionally, I use Rscript in lots of other situations and this seems to be the only place that it fails.

Any help is much appreciated.

like image 823
Erik Shilts Avatar asked Jan 22 '12 20:01

Erik Shilts


1 Answers

Explicitly load the packages methods and utils before loading roxygen2 and calling roxygenize().

#!/usr/bin/env Rscript
library(methods)
library(utils)
library(roxygen2)
roxygenize('.', copy=FALSE)
like image 60
Erik Shilts Avatar answered Oct 03 '22 20:10

Erik Shilts