如何使用特定模块从 R 运行 perl 脚本? [英] How can I run a perl script from R with specific modules?

查看:79
本文介绍了如何使用特定模块从 R 运行 perl 脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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!

最好的,海科

推荐答案

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

The problem you have is that your R Code is using the system perl (5.28) and not your pelbrew perl (5.26.2).

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

You need to do the system2('perl', command) call to use the perlbrew perl instead of the system perl.

要从激活 perlbrew perl 的 shell 执行此操作,请键入 which perl 这应该为您提供 pelbrew 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.

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

Pass this full path as the first argument to the system2(--result of 'which perl'--, command).

这篇关于如何使用特定模块从 R 运行 perl 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆