Search code examples
c#r.net

Use of many names in c# r.net for one variable


It's not like R where we can manipulate many operations for one variables having one name as this example.

DataIns=read.csv(file="C:/Users/isalah/Desktop/Fichiers_CRM/Fichier_csv/Inscrits.csv",sep=";",header=TRUE)
DataIns=DataIns[with(DataIns, order(Id)),]

As you can see the variable DataIns was used tow times and even for other manipulations.

In C#, if I decide to do the equivalent of the code above :

DataFrame testData = engine.Evaluate("DataIns<-read.table('C:/Users/isalah/Desktop/Fichiers_CRM/Fichier_csv/Diagnostic.csv', header=TRUE, sep =';',fill = TRUE)").AsDataFrame();    
DataFrame testData= engine.Evaluate("DataIns=DataIns[with(DataIns, order(Id)),]").AsDataFrame();

It will say that this variable was already defined.

How can I deal with that? Thanks!


Solution

  • When you want to override the testData variable just write this

    DataFrame testData = engine.Evaluate("DataIns<-read.table('C:/Users/isalah/Desktop/Fichiers_CRM/Fichier_csv/Diagnostic.csv', header=TRUE, sep =';',fill = TRUE)").AsDataFrame();    
    testData= engine.Evaluate("DataIns=DataIns[with(DataIns, order(Id)),]").AsDataFrame();
    

    When you want both variables rename the second variable

    DataFrame testData = engine.Evaluate("DataIns<-read.table('C:/Users/isalah/Desktop/Fichiers_CRM/Fichier_csv/Diagnostic.csv', header=TRUE, sep =';',fill = TRUE)").AsDataFrame();    
    DataFrame testDataNew= engine.Evaluate("DataIns=DataIns[with(DataIns, order(Id)),]").AsDataFrame();