4

I have just installed some Perl modules locally in Ubuntu 18.04 LTS.

When calling them using the RStudio Server like this

system("perl -MBio::TreeIO -e 1")

I get the following error

Can't locate Bio/TreeIO.pm in @INC (you may need to install the Bio::TreeIO module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.26.1 /usr/local/share/perl/5.26.1 /usr/lib/x86_64-linux-gnu/perl5/5.26 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.26 /usr/share/perl/5.26 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base)

When I source ~/.bashrc in the terminal everything's ok.

I tried creating a ~/.Rprofile containing:

system(". ~/.bashrc")

but no good.

  • It sounds like the perl that you used to install the modules is different from the one that RStudio uses to run the command. Is there anything in `.bashrc` that changes the contents of `PATH`? – Borodin Apr 30 '18 at 18:52
  • yes! .bashrc contains `PATH="/home/acjfernandes/perl5/bin${PATH:+:${PATH}}"; export PATH; PERL5LIB="/home/acjfernandes/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}"; export PERL5LIB; PERL_LOCAL_LIB_ROOT="/home/acjfernandes/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB_ROOT}}"; export PERL_LOCAL_LIB_ROOT; PERL_MB_OPT="--install_base \"/home/acjfernandes/perl5\""; export PERL_MB_OPT; PERL_MM_OPT="INSTALL_BASE=/home/acjfernandes/perl5"; export PERL_MM_OPT; – anajacintafernandes Apr 30 '18 at 18:55
  • Okay, then you need to persuade RStudio to use the same perl, or you need to install the modules you need in the one RStudio uses. – Borodin Apr 30 '18 at 18:58
  • How so? by installing it system-wide instead of locally? – anajacintafernandes Apr 30 '18 at 19:04
  • 1
    I don't know anything about R or how your system is set up. If you install the modules you need *without* first running `.bashrc` then you should be using the same perl as RStudio. That will be a good start. – Borodin Apr 30 '18 at 19:09
  • Try to specify the path to where you install perl: system("/your/path/to/perl -MBio::TreeIO -e 1") – Katia Apr 30 '18 at 21:27

1 Answers1

4

According to the documentation, accessed by running help(Startup) in the R shell, you should create a file .Renviron in your home directory which will be read when starting up a new R session. For example:

.Renviron

FOOBAR=/foo/bar/foo/bar

R shell

R
R version 3.2.3 (2015-12-10) -- "Wooden Christmas-Tree"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
...

> cat(Sys.getenv("FOOBAR"), "\n")
/foo/bar/foo/bar 

So just create your .Renviron file with the PERL5LIB variable set to your local perl package installation directory.

xxfelixxx
  • 6,512
  • 3
  • 31
  • 38