不久前,您曾经可以安装rcom
package in R to use COM scripting (例如,访问外部程序。)不幸的是,它 seems to be discontinued :
Package ‘rcom’ was removed from the CRAN repository.
Formerly available versions can be obtained from the archive.
This depends on statconnDCOM, which nowadays restricts use, contrary to the CRAN policy for a package with a FOSS licence. See http://rcom.univie.ac.at/ and http://www.statconn.com/.
按照存档和 statconn 链接并在 R 版本 3 中安装旧版本之一会出现错误:
“Error: package ‘rcom’ was built before R 3.0.0: please re-install it”.
我对 R 不太熟悉,但似乎没有办法绕过这个消息 - 毕竟它是在安装时发生的,所以重新安装似乎不是答案。看来 rcom 根本不适用于最近(3.0+)版本的 R。我还扫描了 package list ,虽然搜索“COM”会返回一百多个结果,但我在点击它们时可能错过了正确的结果。
如何使用 rcom
包,或者以其他方式在 R 中使用 COM?
(注:我是代表同事问这个问题的。我自己对R完全没有经验。我们俩在寻找答案时找不到任何东西。我确信其他人也在使用COM不过,在最新版本的 R 中!)
最佳答案
几个月前我查看了 rcom 源代码。看来我可以在 R3.0.1 上构建并安装它。如果有帮助的话,下面是过程。
- 查看 rcom 的最新源代码。我本地有 rcom_2.2-5.tar.gz 。我可以在以下地址上谷歌搜索一些东西,但我不知道出处,所以由你来检查它是否合法。 http://cran.open-source-solution.org/web/packages/rcom/index.html
- 在 R 中做
install.packages('rscproxy')
- 按照 R 网站 ( http://cran.r-project.org/bin/windows/Rtools ) 上的说明安装 Rtools,
- 打开 Windows 命令提示符,即运行“CMD”
转到包含“rcom”文件夹的文件夹,然后在命令提示符处:
set R="c:\Program Files\R\R-3.0.1\bin\i386\R.exe" %R% CMD check --no-manual rcom
检查是否通过,没有太多提示。您对 --no-manual 选项的调用(如果您安装了 MiKTeX,则可以将其删除)
%R% CMD INSTALL rcom
应该导致
installing to c:/Rlib/rcom/libs/i386
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
rcom requires a current version of statconnDCOM installed.
To install statconnDCOM type
installstatconnDCOM()
This will download and install the current version of statconnDCOM
You will need a working Internet connection
because installation needs to download a file.
* DONE (rcom)
在 R 中:
library(rcom) installstatconnDCOM()
我尝试了
comRegisterRegistry() ; comRegisterServer() ; x<-comGetObject("Excel.Application")
但我得到x
的 NULL 。我不是 rcom 的用户,所以虽然一切似乎都编译得很好;它可能不再起作用了。
如果您碰巧需要访问 .NET 代码,一个可行的选择(是的,我有提及它的既得利益)可能是 rClr包。
希望这有帮助;我很想听听你进展如何。
关于r - 如何访问 R v3 中的 Windows COM 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18202999/