Fairly elementary UNIX question

S

Steckly, Ron

Hi,

=20

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?=20

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

=20

Am I completely on the wrong track?

=20

Ron
 
S

Sebastian Hungerecker

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. =A0But I'm not sure how
to script to a terminal....

"script to a terminal" is maybe the wrong term, because there is no termina=
l=20
involved at all (at least no xterm). You want pipes:

require 'open3'
input, output, errors =3D Open3.popen3("R")
input.puts "my_command"
response =3D output.gets
=2E..


HTH,
Sebastian
=2D-=20
Jabber: (e-mail address removed)
ICQ: 205544826
 
K

Ken Bloom

Steckly said:
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?

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
 
R

Robert Klemme

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.

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

M. Edward (Ed) Borasky

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?

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

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!!

4. 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". :)
 
M

M. Edward (Ed) Borasky

M. Edward (Ed) Borasky said:
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

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


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!!

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


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". :)

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top