2
votes

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.

1
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
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
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
How so? by installing it system-wide instead of locally? - anajacintafernandes
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

1 Answers

3
votes

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.