Difference between revisions of "Calling an R function"
Line 10: | Line 10: | ||
=== Installation of R === | === Installation of R === | ||
# [https://cran.r-project.org/bin/windows/base/ Install R] | # [https://cran.r-project.org/bin/windows/base/ Install R] | ||
− | # Install [https:// | + | # Install [https://www.omegahat.net/RDCOMServer/ the RDCOMServer package] for R |
+ | ## Download the Windows Binary ZIP file | ||
+ | ## Unzip it into <code>%R_HOME%\library</code>. For me this was <code>"C:\Program Files\R\R-4.3.0\library"</code> | ||
+ | # Install [https://www.omegahat.net/SWinRegistry/ the SWinRegistry package]. | ||
+ | ## Download the Windows Binary ZIP file | ||
+ | ## Unzip it into <code>%R_HOME%\library</code>. For me this was <code>"C:\Program Files\R\R-4.3.0\library"</code> | ||
+ | ## Run: <code>Rcmd install RWinRegistry</code> | ||
+ | # Install the R package [https://bioconductor.org/install/ Ruuid]. | ||
+ | ## Start R | ||
+ | ## <code>install.packages("BiocManager")</code> | ||
=== Install packages === | === Install packages === |
Revision as of 18:19, 12 June 2023
R is an open source programming language commonly used for data analysis. This page describes how to call an existing R function from a model running in the Analytica Enterprise edition.
Using the RDCOMServer package
One approach of many is to use the RDCOMServer package in R.
Installation of R
- Install R
- Install the RDCOMServer package for R
- Download the Windows Binary ZIP file
- Unzip it into
%R_HOME%\library
. For me this was"C:\Program Files\R\R-4.3.0\library"
- Install the SWinRegistry package.
- Download the Windows Binary ZIP file
- Unzip it into
%R_HOME%\library
. For me this was"C:\Program Files\R\R-4.3.0\library"
- Run:
Rcmd install RWinRegistry
- Install the R package Ruuid.
- Start R
install.packages("BiocManager")
Install packages
- Launch R
- Run:
install.packages("devtools")
devtools::install_github("omegahat/RDCOMServer")
-- This results in an error. RDCOMServer not yet successfully installed. This part is being researched.
Server-side code
- Note: This part is untested, since I haven't yet been able to successful install the required R packages. Work in progress.
Here's example R-code that creates a simple COM server with a single method named multiply:
library(RDCOMServer) serverDesc <- COMCreate("R.Server") serverDesc$setClass("R.Server") # Create the `multiply` method serverDesc$addMethodDef( functionName = "multiply", args = c("x" = "numeric", "y" = "numeric"), return = "numeric", def = function(self, x, y) x * y ) # Register the server serverDesc$register() # Start the server COMServer()
Analytica-side call
- Create the variable:
- Variable RServer ::=
COMCreateObject("R.Server")
- Note: Launch the R-side server before evaluating
RServer
- Variable RServer ::=
- Call the method within a different variable:
- Variable Y ::=
RServer->multiply(5,7)
- Variable Y ::=
Comments
Enable comment auto-refresher