如何在 R v3 中访问 Windows COM 对象? [英] How can I access Windows COM objects in R v3?
问题描述
前段时间,您曾经能够安装 rcom
包在 R 中以使用 COM 脚本(例如,访问外部程序.)不幸的是,它
Some time ago, you used to be able to install the rcom
package in R to use COM scripting (eg, access to external programs.) Unfortunately, it seems to be discontinued:
包rcom"已从 CRAN 存储库中删除.
Package ‘rcom’ was removed from the CRAN repository.
可以从存档中获取以前可用的版本.
Formerly available versions can be obtained from the archive.
这取决于现在限制使用的 statconnDCOM,相反对于具有 FOSS 许可证的软件包的 CRAN 政策.看http://rcom.univie.ac.at/ 和 http://www.statconn.com/.
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 中安装旧版本之一会出现错误:
Following the archive and statconn links and installing one of the older versions in R version 3 gives the error:
错误:包‘rcom’是在 R 3.0.0 之前构建的:请重新安装它".
"Error: package ‘rcom’ was built before R 3.0.0: please re-install it".
我对 R 不是很熟悉,但似乎没有办法绕过这个消息——毕竟它是在安装时发生的,所以重新安装似乎不是答案.似乎 rcom
根本不适用于 R 的最新(3.0+)版本.我还扫描了 包列表,虽然在那里搜索COM"会返回一百多个结果,我可能在点击它们时错过了正确的结果.
I am not very familiar with R, but there seems no way around this message - after all, it occurs when installing, so re-installing doesn't seem to be the answer. It appears as though rcom
is simply not available for recent (3.0+) versions of R. I have also scanned the package list, although searching for "COM" there returns over a hundred results and it is possible I missed the right one when clicking through them.
如何使用 rcom
包,或以其他方式在 R 中使用 COM?
How can I use the rcom
package, or use COM from within R some other way?
(注意:我是代表同事问这个问题.我自己完全没有使用R的经验.我们俩在寻找答案时都找不到任何东西.我相信其他人也在使用COM不过,在最新版本的 R 中!)
(Note: I am asking this question on behalf of a colleague. I have no experience with R myself at all. Both of us, when searching for answers, could not find anything. I am sure that others are also using COM in the latest version of R, though!)
推荐答案
几个月前看的rcom源码.看来我可以让它在 R3.0.1 上构建和安装 OK.如果有帮助,下面是过程.
I looked at the rcom source code a few months ago. It seems I can get it to build and install OK on R3.0.1. Below is the procedure if it helps.
- 查看 rcom 的最新源代码.我在本地有 rcom_2.2-5.tar.gz.我可以在以下地址搜索一些东西,但我不知道出处,所以由你来检查它是否合法.http://cran.open-source-solution.org/web/packages/rcom/index.html
- 在 R 中执行
install.packages('rscproxy')
- 按照 R 网站上的说明安装 Rtools (http://cran.r-project.org/bin/windows/Rtools),
- 打开 Windows 命令提示符,即运行CMD"
转到包含rcom"文件夹的文件夹,并在命令提示符下:
- Get a checkout of the latest source code of rcom. I have rcom_2.2-5.tar.gz locally. I can google something at the following address, but I have no idea of the provenance, so up to you to check it is legit. http://cran.open-source-solution.org/web/packages/rcom/index.html
- in R do
install.packages('rscproxy')
- install Rtools as per the instructions on the R web site (http://cran.r-project.org/bin/windows/Rtools),
- open a Windows command prompt i.e. run "CMD"
go to the folder containing the 'rcom' folder, and at the command prompt:
set R="c:Program FilesRR-3.0.1ini386R.exe"
%R% CMD check --no-manual rcom
检查通过,没有太多抱怨.您对 --no-manual 选项的调用(如果您安装了 MiKTeX,您可以将其删除)
check it passes without too many complaints. Your call as to the --no-manual option (if you have MiKTeX installed you may remove it)
%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 中:
in R:
library(rcom) installstatconnDCOM()
我尝试了
comRegisterRegistry() ;comRegisterServer();x<-comGetObject("Excel.Application")
但我得到x
的 NULL.我不是 rcom 的用户,所以虽然它似乎编译得很好;它可能不再起作用了.I tried a
comRegisterRegistry() ; comRegisterServer() ; x<-comGetObject("Excel.Application")
but I get a NULL forx
. I am not a user of rcom so while it all seems to compile fine; it may just not work anymore.如果您碰巧需要访问 .NET 代码,一个可行的选择(是的,我有兴趣提及它)可能是 rClr 包.
If you happen to need to access .NET code, a viable option (and yes I have a vested interest in mentioning it) may be the rClr package.
希望这会有所帮助;我很想听听你的进展.
Hope this helps; I'd be interested to hear how you go.
这篇关于如何在 R v3 中访问 Windows COM 对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!