Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I am trying to submit a job to be executed on cluster. And this is done by writing an sbatch submission script. The job involves opening R 3.1.3 and running the referenced R script on the server.

Here is the shell script I wrote:

#!/bin/bash
#SBATCH --account=810639
#SBATCH --time=1200
#SBATCH --mem-per-cpu=4096
#SBATCH --ntasks=1
#SBATCH --constraint=normalmem
#SBATCH --output=output_%j.txt
#SBATCH --error=error_output_%j.txt
#SBATCH --job-name=AggrigatePIXEL
#SBATCH --partition=ESG_Std
#SBATCH --mail-type=FAIL
#SBATCH [email protected]
# print date and time
module load R/3.1.3
module load geos/gcc/64/3.4.2
module load netcdf/gcc/64/4.3.3
module load gdal/gcc/64/1.11.1
source('AggrigatePIXEL_Forecast_easyVerfication_SERVERversion.R')

When I try to run the shell script (saved as yate.sh) it gives me the following error message:

./yate.sh: line 20: syntax error near unexpected token
'AggrigatePIXEL_Forecast_easyVerfication_SERVERversion.R'

./yate.sh: line 20: 
source('AggrigatePIXEL_Forecast_easyVerfication_SERVERversion.R')

I know the problem is related to opening and executing the .R script which requires running the R program first. Can anybody help me on how I can instruct this in the shell script?

share|improve this question

1 Answer 1

I'm not familiar with R, but your script is attempting to run as a bash script, not an R script. Change your first line to #!/usr/bin/Rscript or possibly #!/usr/bin/env Rscript. You may need to alter the path to wherever R is on your system.

According to http://stat.ethz.ch/R-manual/R-devel/library/utils/html/Rscript.html it should start like this example:

#! /path/to/Rscript --vanilla --default-packages=utils
args <- commandArgs(TRUE)
res <- try(install.packages(args))
if(inherits(res, "try-error")) q(status=1) else q()`
share|improve this answer
    
I am not trying to run the R script as the bash script @Mel. The bash script is needed to specify the required conditions to the SLURM scheduler which will later start and excute the R script on the cluster after finding a space for my job according to the requirements. –  live fan Jul 6 at 21:17
    
@livefan then after you have done your bash commands, you can call the R script with R -f filename –  Mel Jul 6 at 21:28
    
Thanks @Mel. That is it! it is now working for me, –  live fan Jul 8 at 8:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.