2

The code can run through on my desktop. I tried to run it on a server and got error Error: Package 'RcppArmadillo' referenced from Rcpp::depends in source file is not available. I wonder if something wrong when I installed the packages but I have no idea how to fix it.

The R script is like this

> library(Rcpp,lib="~/R_libs")
> library(RcppArmadillo,lib="~/R_libs")
> library(gtools,lib="~/R_libs")
> Rcpp::sourceCpp('~/Test/probit2.cpp')
Error: Package 'RcppArmadillo' referenced from Rcpp::depends in source 
file probit2.cpp is not available.`

And the cpp file begins with this

#include "RcppArmadillo.h"
// [[Rcpp::depends(RcppArmadillo)]]
using namespace Rcpp;

Thanks in advance!

ying
  • 31
  • 4
  • 2
    Have you tried to extend R’s library path, cf https://stackoverflow.com/questions/15170399/change-r-default-library-path-using-libpaths-in-rprofile-site-fails-to-work – Ralf Stubner Nov 14 '18 at 08:50
  • 2
    "What Ralf said" -- set either `.libPaths()` more permanently, or equivalently one of the environment variables. You tell all the `library()` commands _explicitly_ but assume `sourceCpp()` knows magically by itself. It does not, and you need to help it. See `help(Startup)` for many options. – Dirk Eddelbuettel Nov 14 '18 at 11:46
  • Got it, I set the R_LIBS to my library folder and now it works! Thank you! – ying Nov 14 '18 at 17:51
  • How about adding your solution as an answer? – Ralf Stubner Nov 16 '18 at 12:58

1 Answers1

1

Thanks for all the comments above, I solved this by setting this from the terminal:

export R_LIBS="~/myRlib"
Rscript myscript.r

I could also set .libPaths("~/myRlib") in the R script.

ying
  • 31
  • 4