как выполнить файл .rmd из c# и получить ответ о выполнении - Dot Net - PullRequest
0 голосов
/ 27 марта 2020

У меня есть файл .rmd [файл разметки R], он выполнит проверку данных для определенного сценария c, я хотел выполнить файл rmd из консольного приложения, используя c#, может кто-нибудь мне помочь выполняет казнь.

1 Ответ

0 голосов
/ 05 апреля 2020
Finally I have done the above requirement as below,posting here since it can help some one on implementation
 - created a R script and invoked Rmd script from the R script
 - used command line code for invoking R script from C#.

R Script Sample:

rmarkdown::render(
    input = rmdfilepath, 
    output_file = outputfilepath,
    output_format = "all", output_options = list())

c# Sample:
private static string RunRScript(string rpath, string scriptpath, string inputfilepath, 
                                  string outputfilepath)
        {   
            try
            {


                var info = new ProcessStartInfo
                {
                    FileName = rpath,
                    WorkingDirectory = Path.GetDirectoryName(rpath),
                    Arguments = scriptpath + " " + inputfilepath + " " + outputfilepath,
                    RedirectStandardOutput = true,
                    CreateNoWindow = true,
                    UseShellExecute = false
                };

                using (var proc = new Process { StartInfo = info })
                {
                    proc.Start();
                    return proc.StandardOutput.ReadToEnd();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            return string.Empty;
        }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...