10

I have a friend who asked me to implement something for him. Let's make a simple example: I have four values I enter: Value1 up to Value4. With these values my R program does fancy calculations and gives a nice result.

No let's say I do not want to bother my friend with (from his point of view) complicated r script and entering the values there. So I want to program a simple input gui and then make it an executable file. Now I have two questions:

How can I create such an input gui?

How can I get an executable file out of this?

digEmAll
  • 56,430
  • 9
  • 115
  • 140
Jen Bohold
  • 1,038
  • 2
  • 10
  • 17
  • 5
    How about http://www.rstudio.com/shiny/ ... ? (Not quite an executable file, but ...) – Ben Bolker Dec 21 '13 at 18:12
  • @BenBolker Thanks for the hint! But I do not want to have it as a web application. I really want to program the interface and then have it as an executable file on my pc, which I can sent do my friend. So I am searching for a more "complete" solution. Somehow a 2 step solution: How to get the interface (do it in R, or do it in another language with calling somehow the r procedures) and so. – Jen Bohold Dec 21 '13 at 18:16
  • I think it is not that easy, because If I do it with C, so my C program somehow calls R procedures when I click on certain buttons I need to have a C environment installed and the R environment, right? Should I do it this way? I mean that I program the basic structure of the program (of gui) with C and then calling the R code when a button is clicked? So my friend has to install R and the C environment and then run my program. Or is there a better approach, more easier more integrated? – Jen Bohold Dec 21 '13 at 18:33
  • Find new friends... Uh, this probably depends on the operating system. R usually installs a command line version (e.g. /usr/local/bin/R) that can be accessed via a shell script. You could write a script to accept values, write an R program to a temporary file, run the program and then read the results to the command line. If it's on an OSX machine, applescript is pretty easy to use to do simple stuff like this. – alex keil Dec 21 '13 at 18:33
  • @alexkeil Well, I guess it is on Windows 7? "simple stuff like this". Ok, well, for me it is not so easy. – Jen Bohold Dec 21 '13 at 18:38
  • @Jen I didn't mean to imply this was a simple task - making a gui is not easy unless it's something you've done a lot. One alternative that may be the easiest is writing an R program that just pulls values from a CSV file that your friend can edit any way he/she pleases. Then he/she never has to edit the R script - just edit the CSV and run the script. – alex keil Dec 21 '13 at 18:46
  • 1
    I think it really depends how hard you want your friend to have to work. If you/they are willing to install R and then run a script you send them to install a few add-on packages, and then to click on a script to run `R CMD BATCH ...`, then you have a variety of choices for building GUIs -- the simplest is probably the `tcltk` package http://www.sciviews.org/_rgui/projects/TclTk.html . On the other hand, if you really want a single `.exe` file that you can send them, that's a bit harder ... – Ben Bolker Dec 21 '13 at 18:52
  • http://stackoverflow.com/questions/14096520/compile-r-script-into-standalone-exe-file – Ben Bolker Dec 21 '13 at 18:52
  • http://stackoverflow.com/questions/4918553/what-are-the-ways-to-create-an-executable-from-r-program – Ben Bolker Dec 21 '13 at 18:53
  • http://stackoverflow.com/questions/1452235/does-an-r-compiler-exist (there are variety of reasons people want to build executables, including (1) protecting the source code, (2) having a simple install process. The links I'm posting address various aspects of the problem, hence none of them are *quite* duplicates of this question, but they generally say "no, there's not an easy way to do this" – Ben Bolker Dec 21 '13 at 18:53
  • Would python be an option? – Roman Luštrik Dec 21 '13 at 19:43
  • @RomanLuštrik I don't know, I am not used to python? – Jen Bohold Dec 21 '13 at 19:48
  • 1
    Note that you can run Shiny locally. It doesn't need to be hosted on a server. – Dason Dec 21 '13 at 21:02
  • Pass the input values as commandline arguments to a call to rscript. No need for the GUI. – Thomas Dec 21 '13 at 22:28

1 Answers1

1

You're only supposed to ask one question per post here, and you've asked two.

Here's the answers.

  1. You can create a simple input GUI with the tcltk package. A slightly more interesting one with the rpanel package. A prettier one with the RGtk2 package.

  2. No. Its hard to get an executable file out of anything that includes a GUI, an interpreted language, and a library of functions written in that language. The most reliable way is to zip the entire R installation and your program code into a zipped up, self-extracting executable that unzips itself and runs. Every time you run it.

Spacedman
  • 92,590
  • 12
  • 140
  • 224
  • comments say OP is on windows. Isn't `RGtk2` going to be difficult (at least) to use on windows? – Ben Bolker Dec 21 '13 at 20:35
  • 1
    Personally I think the question needs to be closed for umpteen reasons - "find a tool", "minimal understanding" etc etc. Its turning into a discussion in comments which we don't really want, esp. if the OP isn't updating the question. – Spacedman Dec 21 '13 at 20:38
  • 1
    fair enough, although I thought about writing a canonical answer to "(why can't I/how do I) package a set of R functions as a standalone executable?", which is *not* an unreasonable question. Due to the various reasons people want to do this (compiled code, code obscurity/obfuscation, convenience of installation), the existing answers are somewhat scattered. – Ben Bolker Dec 21 '13 at 20:43