How can I access Windows COM objects in R v3?

后端 未结 3 955
暗喜
暗喜 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:31

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

    0 讨论(0)
  • 2021-01-11 22:35

    New versions of rcom and rscproxy (also for current versions of R) are available from a different repository. Just use http://rcom.univie.ac.at/download as the R repository to install from and you can download and install binary versions of statconn packages from there.

    Hope this helps!

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题