5. Writing and Running a R Program
Create a R Program
Also commonly used in data analysis, R is a programming language that is especially powerful for data exploration, visualization, and statistical analysis. We are going to create a simple visualization program that plots some random data. The R script we are using is included in this directory.
Create a Job Script
Note that unlike the previous examples we have a file we need the program to read. We will need to copy this file to the compute node before running the program. Create a file named
compile_and_run.sh
with the following content:#!/bin/bash #SBATCH --job-name=count_rows #SBATCH --output=result.out #SBATCH --error=result.err #SBATCH --time=00:10:00 #SBATCH --mem=1G module load python/3.8 cp /path/to/your/csvfile.csv $SLURM_TMPDIR # Create a virtual environment and install pandas. python -m venv $SLURM_TMPDIR/venv source $SLURM_TMPDIR/venv/bin/activate pip install pandas python count_rows.py $SLURM_TMPDIR/csvfile.csvSubmit the Job
Use the
sbatch
command to submit your job script:sbatch run_python.shMonitor the Job
Check the Output
Cancel Jobs
Additional Resources
Last modified: 21 March 2025