簡體   English   中英

如何使用特定模塊從 R 運行 perl 腳本?

[英]How can I run a perl script from R with specific modules?

我可以毫無問題地從終端運行 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。

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM