0

I need to execute some R scripts in c# .So I write the code below including R.net package to do interaction between R and c#. It's about importing csv files.

    using RDotNet;

namespace ConsoleApp11
{
    class Program
    {
        static void Main(string[] args)
        {
            REngine engine = REngine.GetInstance();
            DataFrame testData = engine.Evaluate("DataIns<-read.table('C:/Users/isalah/Desktop/Fichiers_CRM/Fichier_csv/Diagnostic.csv', header=TRUE, sep = ';')").AsDataFrame();
            DataFrame DataAch = engine.Evaluate("DataAch=read.table('C:/Users/isalah/Desktop/Fichiers_CRM /Fichier_csv/Achats1.csv',header=TRUE,sep = ';')").AsDataFrame();
            DataFrame DataDia = engine.Evaluate("DataDia=read.table('C:/Users/isalah/Desktop/Fichiers_CRM/Fichier_csv/Diagnostic.csv',header =TRUE,sep = ';')").AsDataFrame();
            DataFrame DataCad = engine.Evaluate("DataCad=read.table('C:/Users/isalah/Desktop/Fichiers_CRM/Fichier_csv/CADEAUX.csv',header =TRUE,sep = ';')").AsDataFrame();

            double v = new double();
            v = testData.ColumnCount;
        }
    }
}

It seems that the program read the first file but It's stopped in the next one showing in the console this error :

Error in file(file, "rt") : cannot open the connection '

How could I solve this problem please?

User2018
  • 61
  • 10
  • 1
    You have spaces in the second filename "Fichiers_CRM /Fichier_csv /Achats1.csv" – Simon Wilson Jan 08 '18 at 12:59
  • I can see at a glance that your first `read.csv` call has spaces after `Ficihers_CRM` and after `Fichier_csv` that don't exist in the following lines. Space are valid path characters, so it's probably pointing to a non-existing folder. – Avner Shahar-Kashtan Jan 08 '18 at 13:00
  • @AvnerShahar-Kashtan, thanks y're right! it was about that but now it show me other error for the end one **'Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : line 23 did not have 12 elements**. Why I got this even I delete all spaces! you can see the edit one now ' – User2018 Jan 08 '18 at 13:18
  • but its complaining about the file contents now.. saying theres not 12 elements. – BugFinder Jan 08 '18 at 13:23
  • It's Ok now thanks .In fact I should add _fill = TRUE_ as proposed here [https://stackoverflow.com/questions/19455070/confusing-error-in-r-error-in-scanfile-what-nmax-sep-dec-quote-skip-nli] by @SimonWilson O'Hanlon – User2018 Jan 08 '18 at 13:24

0 Answers0