What Are the Ways to Create an Executable from R Program

Make a R script executable by sourcing it in a batch file

Found the answer : I tried to use R interactively via batch mode, which obviously couldn't work as batch is non-interactive.

I nevertheless found a workaround thanks to this answer : https://stackoverflow.com/a/11567220/9765404, consisting in downloading R-Portable with all libraries used by my project installed locally and adding this function to the Rprofile.site file (in App/R-Portable/etc) :

.First = function(){ #.First() is the first function R-Portable will execute when opened
.libPaths(.Library) #force R-Portable to use the local library
source("path-to-file") #launches the program
}

Then you can just export the folder containing R-Portable and your project to any Windows computer and execute R-Portable.exe, it works without having R installed.

how to call an executable from R script

To call any external executables you can use the system function:

system("cuda_exe arg1 arg2")

where cuda_exe is the cuda executable, and arg* are the command line arguments passed to the script.

Creating an executable R-file

The tutorial you gave is useful. However, it missed something.
After done all the things in that blog, you still need to do one more thing. Right click on the "test.Rexec" file and choose "open with" and then select "RScript". Maybe you need to find RScript in your system which is usually here:

C:\Program Files\R\R-3.2.1\bin\Rscript.exe

Remeber to check the "Always use the selected program to open this kind of file".
Next time, when you double click the "test.Rexec" file, evethying would be okay.



Related Topics



Leave a reply



Submit