Skip to content

Instantly share code, notes, and snippets.

@nzbart
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nzbart/f48df61f68c4935b337e to your computer and use it in GitHub Desktop.
Save nzbart/f48df61f68c4935b337e to your computer and use it in GitHub Desktop.
This sample plots a simple chart to a PNG file using the R statistical program and R.Net. It requires the R.NET.Community NuGet package to be installed.
using RDotNet;
/*
d:/temp/plot.r:
suppressPackageStartupMessages(library(ggplot2))
library(ggplot2)
p <- qplot(Sepal.Length, Petal.Length, data = iris, color = Species)
png(filename=fileName, width=500, height=500)
plot(p)
dev.off()
*/
class Program
{
static void Main()
{
REngine.SetEnvironmentVariables(); // <-- May be omitted; the next line would call it.
using (REngine engine = REngine.GetInstance())
{
const string fileName = @"D:\temp\image.png";
engine.SetSymbol("fileName", engine.CreateCharacterVector(new []{ fileName }));
engine.Evaluate("source('d:/temp/plot.r')");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment