1

I am using a C# (asp.net MVC) application to create a csv file. This csv file is then used as an input to a R script.

When trying to execute the R script using the csv file created by the application I get the error: cannot open file : Permission denied

However, if I open the csv file and re-save it then the R script executes fine.

My C# code:

if (!System.IO.File.Exists("RCodeInput.csv")) {
   string[] header = new string[] { "ID, FolderName" };
   System.IO.File.WriteAllLines(filename, header);
}

// Within a loop (some logic to create ID and FolderName)
string[] to_write = new string[] { "ID_ToWrite, FolderName_ToWrite" };
System.IO.File.AppendAllLines(filename, to_write);

Any ideas on how to save this with the correct security/permissions?

Hong Ooi
  • 56,353
  • 13
  • 134
  • 187
Zach Dean
  • 11
  • 5
  • May be relevant: http://stackoverflow.com/questions/5156254/closing-a-file-after-file-create. I don't program in C#, but perhaps the write statements are creating an instance of a file object, which locks permissions? Anyway the link may provide an alternate strategy. – mikeck Nov 28 '16 at 00:02
  • 1
    Doesn't seem like an R issue. Seems more like a permissions issue. – IRTFM Nov 28 '16 at 01:03

1 Answers1

0

(Posted on behalf of the OP).

When writing to the csv file in the C# code I made an error by including a comma at the end of the final row (copy and paste error). When using read.csv in R if there is an extra column defined (in comparison to the header) it reads the first column as row names and so this was forcing my columns to be out of sync with what the code was expecting.

halfer
  • 19,824
  • 17
  • 99
  • 186