-1

I have an R package, that depends on the base64enc library. When I run the source file in the package with Rscript:

Rscript analyzer.R

it runs just fine.

The first line in analyzer.R is:

library(base64enc);

However, when I run a function from the package in the repl:

library(analyzer)
analyze()

It complains that base64enc is not installed.

Error in rawToChar(base64decode(mark[1])) :
  could not find function "base64decode"
Calls: analyze ... collect.marks -> lapply -> FUN -> lapply -> FUN -> rawToChar

However, when in the REPL I manually include base64enc:

library(base64enc)
library(analyzer)
analyze()

It works fine. Is there anyway I can tell my analyzer package to use the base64enc library without having to include it in every script every time I use the library?

Nizam
  • 4,569
  • 3
  • 43
  • 60
Leif Andersen
  • 21,580
  • 20
  • 67
  • 100
  • 1
    You should look at the instructions in the [Package Dependencies](http://cran.r-project.org/doc/manuals/R-exts.html#Package-Dependencies) section of [Writing R Extensions](http://cran.r-project.org/doc/manuals/R-exts.html). – Joshua Ulrich May 20 '15 at 20:19

1 Answers1

4

(Note that a script is not a package.)

When you run your script analyzer.R it explicitly loads base64enc so the package is in your load path.

But your package may just have Imports: base64enc with a corresponding NAMESPACE statement -- that makes the code from base64enc available in you package but does not load it.

Back in the day we used to do Depends: base64enc which would load it too -- but clutters the search path. Imports: is better, but has the very side-effect you observe here. So just load the other package at the REPL.

Leif Andersen
  • 21,580
  • 20
  • 67
  • 100
Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725