Calling an R function

Revision as of 18:02, 12 June 2023 by Lchrisman (talk | contribs) (Created page with "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 Enterpr...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.


** This is currently just a place to take notes -- I do not yet have a functioning example **

Using the RDCOMServer package

One approach of many is to use the RDCOMServer package in R.

Installation of R

  1. Install R
  2. Install R tools

Install packages

  1. Launch R
  2. 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 an example 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

  1. Create the variable:
    Variable RServer ::= COMCreateObject("R.Server")
    Note: Launch the R-side server before evaluating RServer
  2. Call the method within a different variable:
    Variable Y ::= RServer->multiply(5,7)
Comments


You are not allowed to post comments.