Skip to content

shell scripts in R

12 messages · Marco Grazzi, Gabor Grothendieck, Andrew Robinson +8 more

#
Hi,

How can I execute some scripts from within R.
I have a large data file which I process (for instance with gawk, but not 
only) before performing some statistics.
I would like to do this in R, so that I do not have to save many data files 
and then making analysis on them (which proved to be unefficient)

Thank you

Marco Grazzi
#
Look at the example that uses gawk and pipe in:

http://finzi.psych.upenn.edu/R/Rhelp02a/archive/59815.html
On 10/13/05, Marco Grazzi <grazzi at sssup.it> wrote:
#
Marco,

use the system command.

?system

I hope that this helps,

Andrew
On Thu, Oct 13, 2005 at 05:14:38PM -0400, Marco Grazzi wrote:

  
    
#
Dnia czwartek, 13 pa??dziernika 2005 23:25, Andrew Robinson napisa??:
system(ls, intern = FALSE, ignore.stderr = TRUE)
Error in as.character(args[[i]]) : cannot coerce to vector

In fact it ignores the stderr !
#
Benedykt P. Barszcz wrote:
Don't you mean system("ls")? See ?system.

Arguments:

command: the system command to be invoked, as a string.

--sundar
#
On Fri, 2005-10-14 at 00:04 +0200, Benedykt P. Barszcz wrote:
As per ?system:

command      the system command to be invoked, as a string.

Thus,

 system("ls", intern = FALSE, ignore.stderr = TRUE)


HTH,

Marc Schwartz
#
Dnia pi??tek, 14 pa??dziernika 2005 00:13, Sundar Dorai-Raj napisa??:
This is the kind of obstacles a newbie has to overcome. Whoeve is writing the 
documentation for R, please do not attempt to save on bytes. Life would be so 
much more pleasureable.... if only it would say "as a quoted string". Jee.
#
Le 13 Octobre 2005 18:39, Benedict P. Barszcz a ??crit??:
In 'system(ls)', 'ls' would be any object, whereas in 'system("ls")', it is a 
string. Specifying "quoted string" would be redundant. (True R wizard can 
correct me if I,m not accurate.)

When I first encountered R's man pages, I thought they were rather sparse 
compared to those of S-Plus. Now I find they are just to the point and so 
much easier to consult!
#
On Fri, 2005-10-14 at 00:39 +0200, Benedict P. Barszcz wrote:
The phrase "quoted string" in my mind is redundant.

If you had taken the time to review the 3 examples provided on the same
page, you would have seen that all three show the use of quotes around
the command and indeed two of the three use the 'ls' command
specifically.

Marc Schwartz
#
First I have to correct myself; there probably is an ls object in your
workspace, but it's a function.

Second I have to suggest you should try to run the example code in the
help file.  Surely this would clarify that the string has to be
quoted?

t1 <- system("who", TRUE)

I'm not so sure that it's a question of saving bytes as a question of
assuming that people will try reasonable avenues.

Cheers

Andrew
On Fri, Oct 14, 2005 at 12:39:59AM +0200, Benedict P. Barszcz wrote:

  
    
#
But,
    > foo <- 'ls'
   > system(foo)
is valid.

Is foo a "string" or a "quoted string"?
Without a doubt, it is the former. But I don't see any quote marks in

    system(foo)

-Don
At 12:39 AM +0200 10/14/05, Benedict P. Barszcz wrote: