[Solved] Running a R script with in a shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Running a R script with in a shell script
# 1  
Old 01-30-2014
[Solved] Running a R script with in a shell script

Hi,

I do have an R script named KO.R. Basically reads thousands of files, whose name has a pattern that differs at a portion of the file name, List.txt.

Row_file1_mile.txt
Row_file2_mile.txt
Row_file3_mile.txt
...
...
Row_file1000_mile.txt

Below is a portion of my Rscript that reads the file.
Code:
vi KO.R

Sample =
  read.delim("/Users/dropBox/Row_$file_mile.txt")
...
...
...

If I provide the list of the variable portion of the file name like

Code:
file1
file2
file3
...
..
file1000

how could I run this script one by one by reading each of the files and execute the script.

This is what I tried by making a .sh file
Code:
while read file
do

R CMD BATCH KO.R 

done < /Users/dropBox/List.txt

where List.txt contains the list of the variable portion of the file.

Could you please let me know the best way to excecute this R script with in the .sh executable shell script?
# 2  
Old 01-30-2014
Try this instead:

Code:
while read file
do

    sed 's/\$file/'"$file"'/g' KO.R > KO_NEW.R
    R CMD BATCH KO_NEW.R
    rm KO_NEW.R

done < /Users/dropBox/List.txt

# 3  
Old 01-30-2014
It didn't work
# 4  
Old 01-30-2014
Can you try the following sed command from the command line and check the new .R file to ensure the replacement you wanted has happened:

Code:
file=file3
sed 's/\$file/'"$file"'/g' KO.R > KO_NEW.R

# 5  
Old 01-30-2014
Thanks. I got it working now.

There was a typo on my side.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Running 3 shell script parallel in another shell script

Hi, I'm trying to do teh below thing. I have a single script which uses 3 different parameters to do 3 different work like belwo. test1.sh par1 -- it shuts down an instance test1.sh par2 -- it shuts down an instance test1.sh par3 -- it shuts down an instance Now I created a script... (7 Replies)
Discussion started by: bhaski2012
7 Replies

2. Shell Programming and Scripting

Shell Script for continuously checking status of a another script running in background, and immedia

Hi, I want to write a script which continuously checking status of a script running in background by nohup command. And if same script is not running then immediately start the script...please help.. i am using below command to run script nohup system_traps.sh & but in some... (9 Replies)
Discussion started by: ketanraut
9 Replies

3. Shell Programming and Scripting

[Solved] Shell script not working in crontab

Hi Iam running below script in crontab but its not working. #!/bin/sh cd /Scripts /usr/local/bin/expect -f /Scripts/bng_backup.exp /Scripts/data.txt tar -cf bngbackup.tar bngbackup ;gzip bngbackup.tar when iam running manually the output file is generating..but bngbackup.tar.gz file... (5 Replies)
Discussion started by: surender reddy
5 Replies

4. Shell Programming and Scripting

[Solved] The SCRIPT command - Can we see the log file of a running session?

Hello. This is my situation. script .anything ls -l . ---How can I see the content of .anything using (i.e) cat .anything? If not possible can someone suggest a sequence to simulate a console-recorder to "observ" from a RUNNING script session? Thanks Paolo Please use code tags... (3 Replies)
Discussion started by: paolfili
3 Replies

5. Solaris

[Solved] Using awk withing a shell script

I am trying to use an awk command within a ksh script but it is not working - I am able to run from command line with no problem. It does not err out - it just does not produce a file with final count. awk "{s+=$0} END {print s}" es.out > es.cntAny help would be greatly appreciated. Thanks (6 Replies)
Discussion started by: bjdamon
6 Replies

6. Shell Programming and Scripting

[Solved] Shell script help

Hi fellas, I have a file that contains text something like this SNAPSHOT snap-021ede4a vol-bc3f89c0 completed 2012-11-19T06:05:26+0000 100% 170495546006 850 Created by CreateImage(i-6adc0515) for ami-977dfafe from vol-bc3f89c0 TAG snapshot snap-021ede4a project PAC TAG snapshot... (5 Replies)
Discussion started by: Kashyap
5 Replies

7. UNIX for Dummies Questions & Answers

[Solved] How to Check if a script is running?

Hi All, I am new to Unix... Can you please let me know how we can check if a script is running or not on Solaris box? (4 Replies)
Discussion started by: Rahul466
4 Replies

8. Shell Programming and Scripting

Bash shell script to check if script itself is running

hi guys we've had nagios spewing false alarm (for the umpteenth time) and finally the customer had enough so they're starting to question nagios. we had the check interval increased from 5 minutes to 2 minutes, but that's just temporary solution. I'm thinking of implementing a script on the... (8 Replies)
Discussion started by: hedkandi
8 Replies

9. Shell Programming and Scripting

[Solved] Looking for script running before I run script again

Good afternoon! I have a script in cron that runs every ten minutes. Normally it only takes a minute or so to complete. However there are times when the amount of data it is looking at is large, and it has taken 20 minutes. So I want for it to look for the script before it starts. I was... (8 Replies)
Discussion started by: brianjb
8 Replies

10. Shell Programming and Scripting

[Solved] Help with running ps -e | less on nano script editor

p { margin-bottom: 0.08in; } This is just a portion of a script I'm writing on Linux nano script editor. When I run the script I get stuck on the ps -e | less command portion of the script:wall:. It displays all the process running but it does not allow me to move to the next line on the script.... (2 Replies)
Discussion started by: SANA4SPA
2 Replies
Login or Register to Ask a Question