rkeshvardoost has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to call R in Perl using RS Perl but I keep geting this error:

Can't locate loadable object for module R in @INC (@INC contains: /usr/local/src/RSPerl/src/ ./ /usr/local/pl/libAll /usr/local/lib64/perl5.16.0/lib /usr/local/perl5.16.0/lib /usr/local/pl/libAll/Statistics-R-0.27/lib /usr/lib/perl5/vendor_perl /usr/local/pl/libAll/Tk /usr/local/pl/libAll/Tk/Event /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .)

I am quite sure that R is installed properly.I am using Perl v5.10.1 , R 3.1.3 and RSPerl 0.92-1.

Here is the code:

sub setup_R { #Uses R library #R= '/usr/local/src/RSPerl/R.pm'; #my $R = Statistics::R->new( bin => $fullpath ); #use lib "/usr/local/src/RSPerl/src/"; #use lib "/usr/local/pl/libAll/Statistics-R-0.27/lib/Statistics/"; #use lib "/usr/local/pl/libAll/Regexp-Common-2011121001/lib/"; #use lib "/usr/local/perl5.16.0/lib/site_perl/5.16.0/"; use lib "/usr/local/src/RSPerl/src/"; use R; #Allows use of R references called between Perl and R use RReferences; #Starts the R module &R::startR("--silent"); #Sets the output for R plots, "pdf" for *.pdf output. "X11" to simply + pull up on screen R::call("pdf"); #Sets the X and Y limits for the plot @xlim=R::c(0,5000); @ylim=R::c(-5,2); #Calls for a blank plot by putting one point at -10,-10 which is off t +he plotting area, sets labels and limits as specified R::callWithNames("plot",{'x',-10,'y',-10,xlim,\@xlim,ylim,\@ylim,x +lab,'Frequency(Hz)',ylab,'LN(A/A0)'});

Replies are listed 'Best First'.
Re: Calling R in Perl using RSPerl
by FreeBeerReekingMonk (Deacon) on Jan 09, 2016 at 23:26 UTC

    I know you said R is installed correctly, but...
    can you do this first RFromPerl.html ? (search for "libR.so")
    Most probable cause: Try checking if you have a shared library:

    Note also that to use the R-in-Perl mechanism one must have built R as + a shared library. (This is not necessary when calling Perl from R.) +You can check if this has been done by checking to see if libR is in +the directory $R_HOME/lib/. If this is not there, you are advised to +clean the entire R distribution (with make distclean) so as to start +from scratch and then configure and compile R using the --enable-R-sh +lib to R's configuration script.

    From a Perl perspective, See also: Re: Can't locate loadable object for module X in @INC (@INC contains: ... )
    Addendum: If not, search your harddisk for R.pm, and hack the INC with it:
    BEGIN { unshift @INC, "/usr/local/src/RSPerl/"; ## include lib };

    But I am sure that in the html page, there is something you need to re-do to get the paths working without hacking them.

    note: you NEED to use the unshift inside that BEGIN block (it executes before all else, thus assuring the @INC is set before it uh... begins... processing your "use R;" statement).

      Hi! Thank you for the suggestion. I have built R as a shared library and the following shows its location: /usr/lib64/R/lib/libR.so /usr/lib64/R/lib/libRblas.so /usr/lib64/R/lib/libRlapack.so What do you think I should do now?

        Add /usr/lib64/R/lib/ to your @INC with the code mentioned before. And also check where R.pm is in, add that path too. You can use multiple unshift commands in that BEGIN block. Outside the block, do a "use R;" and see if that runs without errors.

        BEGIN { unshift @INC, "/usr/lib64/R/lib/"; # unshift @INC, "/other/path/"; # if required }; use R;


        But maybe this works now (this is a use R; without any other code)
        use R;