gpt4 book ai didi

r - 如何从 R 运行带有特定模块的 perl 脚本?

转载 作者:行者123 更新时间:2023-12-02 19:01:11 26 4
gpt4 key购买 nike

我可以从终端运行 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。

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

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

关于r - 如何从 R 运行带有特定模块的 perl 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65553325/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com