【问题标题】:How can I run a perl script from R with specific modules?如何从 R 运行带有特定模块的 perl 脚本?
【发布时间】:2021-01-04 17:01:02
【问题描述】:

我可以毫无问题地从终端运行 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 但不知何故我无法让它工作......有什么想法或想法吗?非常感谢您的帮助!

最好的,海科

【问题讨论】:

  • 您是在 Windows 还是其他操作系统中运行?
  • 我在 MacOs Big Sur 上运行

标签: r perl


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 2014-04-11
    • 2010-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-01
    • 2011-06-15
    • 2012-11-28
    相关资源
    最近更新 更多