Hi all, I am trying to call the R script/ R Program via my Shell Script. I need to pass a file to the R script as an argument. When I am trying to do that I am getting error and only first line of the file is being read. Can you tell me how should I do that so that it reads the entire file in a R object so that later I am able to process the matrix operation on that file. It is a tab delimited file. Thanks. -- Regards, Ayush Raman [[alternative HTML version deleted]]
Hi,
Thanks for the advice but now I am getting an error which states that the R
file/script cannot be opened. Also, my shell and R script is in an
executable mode.
My code is as follows:
#!/bin/bash
DataFile="input.txt"
RProgram="Debug5.R"
outputfile="output_perl_${I}${I}"
time R --slave -f ${RProgram} --args ${DataFile} > ${outputfile}
Regards,
Ayush
---------- Forwarded message ----------
From: Mario Valle <mvalle@cscs.ch>
Date: Sun, Apr 18, 2010 at 1:43 PM
Subject: Re: [R] Table or file as STDIN to the R Script
To: Ayush Raman <ayushraman@gmail.com>
av <- commandArgs(TRUE)
if(length(av) < 1) stop("Missing argument")
r <- read.table(av[1])
Then call your script as:
R --slave -f your-script.r --args the-filename-to-be-read.dat
Hope it helps
mario
On 18-Apr-10 18:57, Ayush Raman wrote:
> Hi all,
>
> I am trying to call the R script/ R Program via my Shell Script. I need to
> pass a file to the R script as an argument. When I am trying to do that I
> am
> getting error and only first line of the file is being read. Can you tell
> me
> how should I do that so that it reads the entire file in a R object so that
> later I am able to process the matrix operation on that file. It is a tab
> delimited file.
>
> Thanks.
>
>
--
Ing. Mario Valle
Data Analysis and Visualization Group |
http://www.cscs.ch/~mvalle <http://www.cscs.ch/%7Emvalle>
Swiss National Supercomputing Centre (CSCS) | Tel: +41 (91) 610.82.60
v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax: +41 (91) 610.82.82
--
Regards,
Ayush Raman
[[alternative HTML version deleted]]
Hi, I found my mistake after a week and yeah the above code by Mario works. I apologize for my previous post which says that it does not work. It was my fault as I made a blunder. Thanks a lot for the same. I am trying to redirect my output generated through my R script in the shell script by using : R --slave -f your-script.r --args the-filename-to-be-read.dat > out1.txt but, it does not direct the output to the file rather it shows me the output on the on shell window. I am not sure why I am not getting it. Can you please help me in this regard ? Thanks again. I appreciate your help. Regards, Ayush On Sun, Apr 18, 2010 at 1:43 PM, Mario Valle <mvalle@cscs.ch> wrote:> av <- commandArgs(TRUE) > if(length(av) < 1) stop("Missing argument") > r <- read.table(av[1]) > > Then call your script as: > > R --slave -f your-script.r --args the-filename-to-be-read.dat > > Hope it helps > mario > > > > On 18-Apr-10 18:57, Ayush Raman wrote: > >> Hi all, >> >> I am trying to call the R script/ R Program via my Shell Script. I need to >> pass a file to the R script as an argument. When I am trying to do that I >> am >> getting error and only first line of the file is being read. Can you tell >> me >> how should I do that so that it reads the entire file in a R object so >> that >> later I am able to process the matrix operation on that file. It is a tab >> delimited file. >> >> Thanks. >> >> > -- > Ing. Mario Valle > Data Analysis and Visualization Group | > http://www.cscs.ch/~mvalle <http://www.cscs.ch/%7Emvalle> > Swiss National Supercomputing Centre (CSCS) | Tel: +41 (91) 610.82.60 > v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax: +41 (91) 610.82.82 >-- Regards, Ayush Raman [[alternative HTML version deleted]]