Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access Windows COM objects in R v3?

Tags:

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:

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/.

Following the archive and statconn links and installing one of the older versions in R version 3 gives the error:

“Error: package ‘rcom’ was built before R 3.0.0: please re-install it”.

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.

How can I use the rcom package, or use COM from within R some other way?

(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!)

like image 895
David Avatar asked Aug 13 '13 07:08

David


2 Answers

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.

  • 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 Files\R\R-3.0.1\bin\i386\R.exe"
    %R% CMD check --no-manual rcom
    
  • 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
    

should result in

    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)
  • in R:

    library(rcom)
    installstatconnDCOM()
    
  • I tried a comRegisterRegistry() ; comRegisterServer() ; x<-comGetObject("Excel.Application") but I get a NULL for x. I am not a user of rcom so while it all seems to compile fine; it may just not work anymore.

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.

like image 104
j-m Avatar answered Oct 12 '22 14:10

j-m


This really should be a comment, but I don't have enough rep points yet to leave one. I found that the above steps did not work for me, but the answer posted by Lisa Ann on this question, RExcel in R 3.0.x, did solve my problem installing rcom. Since you need rcom to run RExcel, the initial steps to install RExcel cover installing rcom on newer versions of R (such as 3.0.2).

Specifically, following the advice on statconn's wiki, http://homepage.univie.ac.at/erich.neuwirth/php/rcomwiki/doku.php?id=wiki:how_to_install

You also need to follow these instructions if you upgrade R, i.e. you install a new >release of R after you have installed RExcel.

Download the statconn DCOM server and execute the program you downloaded Start R as administrator (on Windows 7 you need to right-click the R icon and click the >corresponding item) In R, run the following commands (you must start R as administrator to do this)

install.packages(c("rscproxy","rcom"),repos="http://rcom.univie.ac.at/download",lib=.Library)

library(rcom)

comRegisterRegistry()

Now you have rcom installed, [instructions for installing RExcel follow...]

like image 33
Woodstock Avatar answered Oct 12 '22 14:10

Woodstock