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:

#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 --mail-user=tewodros.yate@wur.nl
# 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

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

./yate.sh: line 20: 

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?


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()`
  • 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 '15 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 '15 at 21:28

Instead of source() run with Rscript:

Rscript AggrigatePIXEL_Forecast_easyVerfication_SERVERversion.R

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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