Reputation: 65
I can run a perl script "myperlscript.pl" from Terminal without any problems. However, if I try to run the same perl script from within RStudio, it gives me the following error:
command <- "myperlscript.pl outputfile.txt"
system2('perl', command)
Can't locate Sort/Fields.pm in @INC (you may need to install the Sort::Fields module)
(@INC contains:
/Library/Perl/5.28/darwin-thread-multi-2level
/Library/Perl/5.28
/Network/Library/Perl/5.28/darwin-thread-multi-2level
/Network/Library/Perl/5.28
/Library/Perl/Updates/5.28.2
/System/Library/Perl/5.28/darwin-thread-multi-2level
/System/Library/Perl/5.28
/System/Library/Perl/Extras/5.28/darwin-thread-multi-2level
/System/Library/Perl/Extras/5.28) at myperlscript.pl line 4.
BEGIN failed--compilation aborted at myperlscript.pl line 4.
I have the Sort::Fields module installed in /Users/admin/perl5/perlbrew/perls/5.26.2/lib/site_perl/5.26.2 and it works fine using Terminal but it seems that perl in RStudio does not index that directory for perl modules - I tried adding it to @INC but somehow I cannot get it to work... any thoughts or ideas? Help is greatly appreciated!
Best, Heiko
Upvotes: 2
Views: 1040
Reputation: 611
The problem you have is that your R Code is using the system perl (5.28) and not your pelbrew perl (5.26.2).
You need to do the system2('perl', command)
call to use the perlbrew perl instead of the system perl.
To do so from your shell where your perlbrew perl is activated type which perl
this should give you the full path to your pelbrew perl.
Pass this full path as the first argument to the system2(--result of 'which perl'--, command)
.
Upvotes: 5