How can I access Windows COM objects in R v3?

后端 未结 3 976
暗喜
暗喜 2021-01-11 21:46

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:

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-11 22:49

    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.

提交回复
热议问题