加载gdata包时如何解决Perl警告消息?

问题描述

我已经更新了StrawBerry Perl 64-bit 5.30.2001gdata软件包。现在,在加载library(gdata)时,我总是收到与Perl相关的警告消息。

suppresspackageStartupMessages(library(gdata))
# Warning messages:
#   1: In system(cmd,intern = intern,wait = wait | intern,show.output.on.console = wait,:
#     running command 'C:\Windows\system32\cmd.exe /c ftype perl' had status 2
#   2: In system(cmd,:
#     running command 'C:\Windows\system32\cmd.exe /c ftype perl' had status 2

但是,我需要的功能read.xls似乎运行良好,只是每次使用警告都会重复一次。

read.xls("http://file-examples-com.github.io/uploads/2017/02/file_example_XLS_10.xls")
# trying URL 'http://file-examples-com.github.io/uploads/2017/02/file_example_XLS_10.xls'
# Content type 'application/vnd.ms-excel' length 8704 bytes
# downloaded 8704 bytes

#   X0 First.Name Last.Name Gender       Country Age       Date   Id
# 1  1      Dulce     Abril Female United States  32 15/10/2017 1562
# 2  2       Mara Hashimoto Female Great Britain  25 16/08/2016 1582
# 3  3     Philip      Gent   Male        France  36 21/05/2015 2587
# 4  4   Kathleen    Hanner Female United States  25 15/10/2017 3549
# 5  5    Nereida   Magwood Female United States  58 16/08/2016 2468
# 6  6     Gaston     Brumm   Male United States  24 21/05/2015 2554
# 7  7       Etta      Hurn Female Great Britain  56 15/10/2017 3598
# 8  8    Earlean    Melgar Female United States  27 16/08/2016 2456
# 9  9   Vincenza   Weiland Female United States  40 21/05/2015 6548
# Warning messages:
#   1: In system(cmd,:
#     running command 'C:\Windows\system32\cmd.exe /c ftype perl' had status 2

我不确定如何处理此警告,因为它对我没有任何帮助,我可能会忽略它,并在其周围加上suppressWarnings()

尽管如此,有人知道解决此问题的方法吗?我无法通过谷歌搜索找到任何东西,也不知道从哪里开始以及实际出了什么问题。

> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  Grdevices utils     datasets  methods   base     

other attached packages:
[1] gdata_2.18.0

loaded via a namespace (and not attached):
[1] compiler_4.0.2 tools_4.0.2    gtools_3.8.2  

解决方法

对于新安装的R,gdata和Strawberry Perl,我也遇到了同样的问题。我终于发现this answer是另一个(但相关)的问题。根据那里的建议,我在提升命令提示符下运行了以下命令:

FTYPE perl=C:\Strawberry\perl\bin\perl.exe %1 %*

这为我解决了问题-但是:我不确定是否像这样设置FTYPE可能会产生任何不良影响。所以要小心。


更新:对我来说, did 上面的命令禁止显示警告“ ftype perl'的状态为2”,但是gdata仍然存在问题:

gdata:无法加载read.xls()所需的perl库 gdata:支持“ XLSX”(Excel 2007+)文件。

gdata:运行功能'installXLSXsupport()' gdata:自动下载并安装perl gdata:支持Excel XLS和XLSX格式所需的库。

但是,installXLSXsupport()失败,并显示错误消息。

然后我跑了

Sys.which("perl")
                              perl 
"C:\\rtools40\\usr\\bin\\perl.exe" 

并意识到RTools的Perl版本优先于我的Strawberry Perl安装–显然gdata不“喜欢”该Perl版本。

因此,我决定通过更改.Renviron文件(usethis::edit_r_environ())来赋予Strawberry Perl优先于RTools:

PATH="${RTOOLS40_HOME}\usr\bin;${PATH}" # old
PATH="${PATH};${RTOOLS40_HOME}\usr\bin" # new

同样,我不确定这 可能带来的后果,但它为我解决了gdata。 也许仅调整PATH也会达到目的(没有我先做过的ftype特技),但是我无法再对此进行测试了。

我的建议:

  1. 首先调整PATH
  2. 如果gdata仍然抱怨ftype,请设置ftype