Compile R script into standalone .exe file?
Is there an easy way to compile my R
script into standalone .exe
file just like what matlab does?
Solution 1:
As a matter of fact there is a way to achieve solution that would meet your requirements. Have a look at the article on Deploying Desktop Apps with R on R-Bloggers. As detailed in the article, you will end up using a few more things than a single exe file.
Also I would like to draw your attention to the RGtk2 with use of the RGtk2 you could attempt to develop your own interface in R. If push comes to shove, I trust that you could pack your R code together with a portable version of R and dependencies into one installer and make and app from that, that would create an illusion of a single exe file.
In your question you asked whether it's easy to develop a standalone executable file interpreting R code. I wouldn't say it's easy. If you have a strong desire to run a R code from an application, you could do it in a simpler manner using RCaller for Java or R.NET.
Solution 2:
In response to your comment:
Actually I would like to distribe it but keeping the scripts and algorithm secret, is there a way to encrypt that or any other way to achieve this purpose?
You can (sort of) do this by saving functions using save()
. For example, here's a function f()
you want to keep secret:
f <- function(x, y) {
return(x + y)
}
Save it wherever:
save(f, file = 'C:\\Users\\Joyce\\Documents\\R\\Secret.rda')
And when you want to use the function:
load("C:\\Users\\Joyce\\Documents\\R\\Secret.rda")
I would save all my functions in separate files, put them in a folder and have one plain old .R script loading them all in and executing whatever. Zip the whole thing up and distribute it to whoever. Maybe even compile it into a package. Effectively the whole thing would be read-only then.
This solution isn't that great though. You can still see the function in R by typing the name of the function so it's not hidden in that sense. But if you open the .rda files their contents are all garbled. It all depends really on how experienced the recipients of your code are with R.
Solution 3:
One form of having encrypted code is implemented in the petals
function in the TeachingDemos package.
Note that it would only take intermediate level programing skills to find the hidden code, however it does take deliberate effort and the user would not be able to claim having seen the code by accident. You would then need some type of license agreement in place to enforce any no peeking agreements.
Solution 4:
Well you are going to need R installed on the deployment machine. As for making an executable, I'm not sure that's possible. But you can create another program that invokes your R script. R is an interpreted language. It is not possible.