Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running Rdotnet without having R installed #125

Open
randbrown opened this issue May 12, 2020 · 5 comments
Open

Running Rdotnet without having R installed #125

randbrown opened this issue May 12, 2020 · 5 comments

Comments

@randbrown
Copy link

According to the readme, "R needs not necessarily be installed as a software on the executing machine, so long as DLL files are accessible". How does one package a C# desktop application (distributing the R DLLs) in such a scenario so the end users do not have to download and install R separately? In my case, I only need to support Windows platform and .NET Framework 4.5.2+. Can the R binaries be xcopy deployed along with the application?

@lrasmus
Copy link
Contributor

lrasmus commented May 24, 2020

Interesting, I actually didn't catch that part of the README! I'm wondering if @jmp75 can confirm that's still the case? I'm not actually sure what it would take to get this up and running, since it seems like you would still need to set some environment variables, and I know there are a lot of registry checks.

Just curious about the desire to deploy without having R installed - is it to simplify deployment to users?

@randbrown
Copy link
Author

Yes, the reason is to simplify the installation of my software package for my end users. My end users are not developers, so they're not going to have R installed by default. So if I can just package the minimal R libraries sufficient to run a couple of R files from my C# app it would simplify things greatly. (In my case another organization has provided a complicated algorithm written in R, and I just want to be able to bundle it with my app and call it if possible, without having to worry about R being installed and configured). I saw the quote in the Readme under the software requirements section, and was hopeful that this scenario is possible. Thanks!

@kingcrimsontianyu
Copy link

@randbrown @lrasmus I deployed a medical imaging software on PCs without R installation. On my developers PC I wrote cmake code to copy the entire system R distribution (C:\Users\[username]\R\R-3.6.3) to the desired directory (e.g. Debug/Release at build time, cmake installation directory at install/package time), and package the software in .msi format that includes the R distribution.

In C# the R engine is initialized in the following way:

try
{
	// this is where I copied the system R distribution to
	string temp = Application.StartupPath + Path.DirectorySeparatorChar + "R-engine";

	string subDirName;
	if(Environment.Is64BitProcess)
	{
		subDirName = "x64";
	}
	else
	{
		subDirName = "i386";
	}

	// note how rPath and rHome are set up
	string rPath = temp + Path.DirectorySeparatorChar + "bin" + Path.DirectorySeparatorChar + subDirName;
	string rHome = temp;
	REngine.SetEnvironmentVariables(rPath, rHome);

	RDotNet.StartupParameter param = new StartupParameter();
	param.Interactive = true;
	param.Quiet = false;

	// by default: string dll = null, bool initialize = true, StartupParameter parameter = null, ICharacterDevice device = null
	REngine engine = REngine.GetInstance(null, true, param, null);

	// by default: StartupParameter parameter = null, ICharacterDevice device = null, bool setupMainLoop = true
	engine.Initialize(param, null, true);

	return engine;
}
catch (Exception ex)
{
	// rethrow a simplified exception
	string msg = "Missing R engine.";
	throw new Exception(msg);
}

Hope this helps.

@lrasmus
Copy link
Contributor

lrasmus commented Oct 7, 2020

Thanks @kingcrimsontianyu !

@randbrown
Copy link
Author

Thanks @kingcrimsontianyu I will look into trying this, whenever I get back onto that project. Thanks for showing your example code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants