# Fairly elementary UNIX question

**URL:** <https://www.ruby-forum.com/t/fairly-elementary-unix-question/123996>\
**Category:** Ruby\
**Created:** [December 23, 2007, 7:22am UTC](https://www.ruby-forum.com/t/fairly-elementary-unix-question/123996 "2007-12-23T07:22:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![StecklyS\_Ron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dfb087/32.png) [@StecklyS\_Ron](https://www.ruby-forum.com/u/StecklyS_Ron)\
**Post date:** [December 23, 2007, 7:22am UTC](https://www.ruby-forum.com/t/fairly-elementary-unix-question/123996/1 "2007-12-23T07:22:54Z")

</div>

Hi,

I’ve been learning a lot about the .NET architecture and scripting to it  
using Visual Basic and C#. I’m trying to write a program right now in  
UNIX and I’m a little perplexed. How do I tap into events in UNIX? For  
example, if I were to write a script to enter a command into the R  
Statistics Program running in Linux, how would I do that?

Normally, in bash I would type R

And a new prompt comes up and you can type whatever command you want.

I’d like to be able to make a simple GUi for it so that its easier for  
people to enter commands who are still learning R. But I’m not sure how  
to script to a terminal…

Am I completely on the wrong track?

Ron

---

<div class="post-metadata">

**Author:** ![StecklyS\_Ron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dfb087/32.png) [@StecklyS\_Ron](https://www.ruby-forum.com/u/StecklyS_Ron)\
**Post date:** [December 23, 2007, 9:42am UTC](https://www.ruby-forum.com/t/fairly-elementary-unix-question/123996/2 "2007-12-23T09:42:03Z")

</div>

Steckly, Ron wrote:

> I’d like to be able to make a simple GUi for [R] so that its easier for  
> people to enter commands who are still learning R. But I’m not sure how  
> to script to a terminal…

“script to a terminal” is maybe the wrong term, because there is no  
terminal  
involved at all (at least no xterm). You want pipes:

require ‘open3’  
input, output, errors = Open3.popen3(“R”)  
input.puts “my\_command”  
response = output.gets  
…

HTH,  
Sebastian

---

<div class="post-metadata">

**Author:** ![StecklyS\_Ron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dfb087/32.png) [@StecklyS\_Ron](https://www.ruby-forum.com/u/StecklyS_Ron)\
**Post date:** [December 23, 2007, 8:11pm UTC](https://www.ruby-forum.com/t/fairly-elementary-unix-question/123996/3 "2007-12-23T20:11:04Z")

</div>

Steckly, Ron [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’d like to be able to make a simple GUi for it so that its easier for  
> people to enter commands who are still learning R. But I’m not sure how  
> to script to a terminal…
> 
> Am I completely on the wrong track?

On UNIX, terminal programs simply have a few open pipes (which behave  
like files) by default, the standard input, standard output, and  
standard error. When you start a new program, the calling program is  
given the other end of each of those pipes. (It’s a little more  
complicated, but various ruby libraries abstract away the compliation  
and make this process appear exactly as I said it.) When a program  
runs in a terminal on UNIX, the terminal is the calling process. All  
the terinal does is display the data that’s written to stdout and  
stderr, and takes keyboard input and sends it to stdin. When  
Ruby calls a program, Ruby is the calling process, and you can use the  
pipes however you want. You can get access to the pipes by using popen  
(built-in) or the Open3 or Open4 libraries.

Note that if you want the output of R to appear on Ruby’s calling  
terminal, you have to do a little work to put the output there  
yourself.

–Ken

---

<div class="post-metadata">

**Author:** ![StecklyS\_Ron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dfb087/32.png) [@StecklyS\_Ron](https://www.ruby-forum.com/u/StecklyS_Ron)\
**Post date:** [December 23, 2007, 8:51pm UTC](https://www.ruby-forum.com/t/fairly-elementary-unix-question/123996/4 "2007-12-23T20:51:00Z")

</div>

On 23.12.2007 19:57, Ken B. wrote:

> > 
> 
> complicated, but various ruby libraries abstract away the compliation  
> yourself.  
> Sorry to nitpick, but if you start a program from the shell without a  
> pipeline and any redirections , stdout, stderr and stdin are not  
> connected to pipes but to devices of the terminal. (This is also true  
> for the shell’s own file descriptors 0, 1 and 2.)

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![StecklyS\_Ron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dfb087/32.png) [@StecklyS\_Ron](https://www.ruby-forum.com/u/StecklyS_Ron)\
**Post date:** [December 23, 2007, 9:13pm UTC](https://www.ruby-forum.com/t/fairly-elementary-unix-question/123996/5 "2007-12-23T21:13:52Z")

</div>

M. Edward (Ed) Borasky wrote:

> > Am I completely on the wrong track?
> 
> 1. In terms of learning R from a GUI, I highly recommend the R Commander
> 
> the language.
> 
> Now, if you’re an experienced Ruby GUI programmer and want to build your  
> own, there’s an R - Ruby bridge called “rsruby”, which I think is in the  
> RubyGems repository. It’s a little tricky to install – some Linux  
> distros don’t put things in exactly the right place. But once you get it  
> installed, a Ruby program can interact with R without all the “shell and  
> pipe nonsense”. 🙂

P.S.: I just did this on my system and there’s a dependency on  
“unixODBC” on a Linux box. On a Windows system, ODBC is already there.  
🙂

---

<div class="post-metadata">

**Author:** ![StecklyS\_Ron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dfb087/32.png) [@StecklyS\_Ron](https://www.ruby-forum.com/u/StecklyS_Ron)\
**Post date:** [December 23, 2007, 9:08pm UTC](https://www.ruby-forum.com/t/fairly-elementary-unix-question/123996/6 "2007-12-23T21:08:34Z")

</div>

Steckly, Ron wrote:

> Normally, in bash I would type R
> 
> And a new prompt comes up and you can type whatever command you want.
> 
> I’d like to be able to make a simple GUi for it so that its easier for  
> people to enter commands who are still learning R. But I’m not sure how  
> to script to a terminal…
> 
> Am I completely on the wrong track?

Well … not so much on the wrong track as on the wrong mailing list. 🙂  
But since I’m an R programmer, I’ll give you the R answer. 🙂

1. On _Windows_, there is an excellent GUI/IDE available for the  
language – the base Windows R installation.

2. There is a mailing list devoted to R GUI packages, which is at  
[https://stat.ethz.ch/mailman/listinfo/r-sig-gui](https://stat.ethz.ch/mailman/listinfo/r-sig-gui)

3. In terms of learning R from a GUI, I highly recommend the R Commander  
library. Assuming you want to make this available to other users or you  
have R installed at the system level, become root, start up R and type

> install.packages(“Rcmdr”, depend=c(“Depends”, “Suggests”, “Imports”))

You’ll need the Tcl/Tk stuff in R for this to work, so if your R doesn’t  
have that, you’ll need to rebuild it. Note that the above will also work  
on the Windows R!!

1. Now you have R Commander installed. At the R prompt, type

> library(Rcmdr)

This brings up the GUI. What’s nice about R Commander is that it allows  
you to capture the script and its output from everything you’ve done. In  
addition, if you drag in all the dependencies, you get some of the more  
convenient functionality like scatterplot matrices, etc., built in.

I should note that the philosophy of R (and its ancestor S) it that it  
_is_ a programming language, and even if you do have a “fancy GUI” like  
SPSS or Minitab, that’s only a “crutch” until you learn to program in  
the language.

Now, if you’re an experienced Ruby GUI programmer and want to build your  
own, there’s an R - Ruby bridge called “rsruby”, which I think is in the  
RubyGems repository. It’s a little tricky to install – some Linux  
distros don’t put things in exactly the right place. But once you get it  
installed, a Ruby program can interact with R without all the “shell and  
pipe nonsense”. 🙂
