none
Accessing List (complex list) as output Parameter of a function RRS feed

  • Question

  • I am using IRIS dataset and wrote our own LinearRegression function. It has Lmmod (Trained Model)  & PredObj (Prediction output). Below are  the content of these objects. 


    lmmod
    Names(lmmod)
     [1] "coefficients"  "residuals"     "effects"       "rank"   "fitted.values" "assign"        "qr"            "df.residual"  
     [9] "contrasts"     "xlevels"       "call"          "terms"      "model"     

    Call: lm(formula = formula, data = data)
    Coefficients:
               (Intercept)                 sepal_w                 petal_l  
                    2.1860                  0.4783                  0.8637  
                   petal_w  speciesIris-versicolor   speciesIris-virginica  
                   -0.3393                 -0.8078                 -1.1448  







    PredObj
    $predictions
        actual     pred
    1      5.1 5.001201
    7      4.6 4.919441
    11     5.4 5.183219
    …..

    $prediction_file_name
    [1] "linear_model_predicted"

    $efficiency
    $efficiency$variance_explained
    [1] 83.17

    $efficiency$mape
    [1] 4.257861

    $efficiency$accuracy
    [1] 95.74

    $efficiency_file_name
    [1] "linear_model_efficiency"

    As you can see it a complex list (list&dataframe inside a list). I am not able to get that as output parameter. What is a best way to access the object in C# (I am executing the function using endpoint/webService, i.e. the usual route). In 8.0.5 we could access any object by converting them to RClient.RData (Name, Type, Object)  and later doing the required manuipulation in C# code. Is there an equivalant of this in 9.0.1 ??


    satyaganti

    Wednesday, March 29, 2017 6:50 AM

Answers

  • made sure all the list and dataframes has proper names for each and every object. Then used RJSON to convert the content to JSON so that application can use it as needed.

    satyaganti

    • Marked as answer by Satyaganti Friday, April 21, 2017 11:06 AM
    Friday, April 21, 2017 11:06 AM

All replies

  • To my knowledge you will not be able to directly work with the entire list in C#. Take a look at the R.NET package, which can handle some R object types:

    https://rdotnet.codeplex.com/

    I would also take a look at the 'rClr' package on CRAN. 

    It can handle dataframes and matrices. You will probably need to parse the list in your C# code and pass a single dataframe as the input argument to your function or routine.

    Hope this helps.

    Stephen Weller

    Wednesday, April 12, 2017 1:11 PM
  • made sure all the list and dataframes has proper names for each and every object. Then used RJSON to convert the content to JSON so that application can use it as needed.

    satyaganti

    • Marked as answer by Satyaganti Friday, April 21, 2017 11:06 AM
    Friday, April 21, 2017 11:06 AM