Background Color:
Background Pattern:
Monday, July 16, 2018
menu click

RNetWeb Code

RNetWeb uses R to perform the statistical calculations and to save the results, data and other information. All infomation for an analysis is saved in a .RData file

The datalayer of the webapplication form the interface to R, it translates the commands into R commands. For example if the program needs to know which variables are in a dataset, it call the propperty DataVariables (in the Class R) this propperty executes the command "names(Data)" on the current loaded .RData file

public string[] DataVariables
    string cmdVars = "names(Data)";
    object result = Evaluate(cmdVars);
    return ((string[])result);

The code for this layer can be found in:


The web application uses R-(D)COMstatconnDCOM to run R and execute commands in R.

How to use RDCOM from a web application

  1. Download and install RDCOM on the webserver
  2. Start R. From the menu choose: packages, install packages and install the rcom library
  3. Give the webuser account permission to create RDCOM instances.
    1. Start, Run - dcomcnfg
    2. Under my computer, DCOM config, select StatConnectorSrv and right click - properties
      Under Security give the webiste account the launch permission (the account name depends on the configuration of your webserver, but mostly this is eihter 'NETWORK SERVICE', ASP or IUSR_machinename)
  4. When developping in Visual Studio, add a reference in your project to the StatConnector dll
  5. In your page you can now use R, for example:
StatConnectorClass _statCon = new STATCONNECTORSRVLib.StatConnectorClass();
string cmdVars = "names(Data)";
object result = _statCon.Evaluate(cmdVars);
return ((string[])result);


RDCOM can only return basic data types such as text and numbers and arrays of basic types. So you cannot use the command that return a complex type, eg _StatCon.Evalualte("lm(......)")

So how can I retrieve complex datatypes, such as models?

  • If you know what value you need you can retrieve that one. eg pvalue by Evalualte("lm(......)$pvalue")
  • Or by several steps to 'ask' what info is available
    • StatCon.EvalualteNoReturn("mymodel<-lm(......)")
    • names=StatCon.Evalualte("names(mymodel)")
    • for each string name in names ....
      • val = StatCon.Evaluate("mymodel$"+name)

I have created classes that retrieve specific values for models and a RVar class that iterative retrieves all info in a complex data type

Error messages are not informative on the cause of the error, so how to get more info?

  • Open the .RDatafile from R and try the command there
  • Remember that you cannot return complex types
  • Use a CharDevice. and print command, eg print(mymod<-lm(...)) Now the R results are as text available in the CharDevice