Fairly elementary UNIX question

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

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

Steckly, Ron [email protected] 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

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

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”. :slight_smile:

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.
:slight_smile:

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. :slight_smile:
But since I’m an R programmer, I’ll give you the R answer. :slight_smile:

  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

  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”. :slight_smile:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs