如何使用特定模块从R运行perl脚本?

我可以从终端运行 perl 脚本“myperlscript.pl”,没有任何问题。但是,如果我尝试从 RStudio 中运行相同的 perl 脚本,则会出现以下错误:

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.

我在 /Users/admin/perl5/perlbrew/perls/5.26.2/lib/site_perl/5.26.2 中安装了 Sort::Fields 模块,它使用终端工作正常,但似乎 RStudio 中的 perl 没有索引该目录对于 perl 模块 - 我尝试将它添加到 @INC 但不知何故我无法让它工作......有任何想法或想法吗?非常感谢帮助!

最好的,海科

回答

您遇到的问题是您的 R 代码使用的是系统 perl (5.28) 而不是您的 pelbrew perl (5.26.2)。

您需要system2('perl', command)调用以使用 perlbrew perl 而不是系统 perl。

要从激活which perlperlbrew perl 的shell 执行此操作,请键入这应该为您提供 pelbrew perl 的完整路径。

将此完整路径作为第一个参数传递给system2(--result of 'which perl'--, command).


以上是如何使用特定模块从R运行perl脚本?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>