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;
}