-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_command_line.R
More file actions
executable file
·31 lines (23 loc) · 1.03 KB
/
simple_command_line.R
File metadata and controls
executable file
·31 lines (23 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/env Rscript
#SBATCH --cpus-per-task 2
#SBATCH --mem-per-cpu 4G
#SBATCH --mail-type END,FAIL
# You can have as many positional arguments as you want
# You can call your R script with sbatch, you can run it thus:
# module load slurm R
# sbatch simple_command_line.R input1 input2 input3
# Or, if not on the cluster, you can run it with Rscript:
# Rscript simple_command_line.R input1 input2 input3
# Or, since it has the Rscript in the shebang:
# ./simple_command_line.R input1 input2 input3
args <- commandArgs(trailingOnly = TRUE)
my_var_1 <- args[1] # First positional argument
my_var_2 <- args[2] # Second positional argument
my_var_3 <- args[3] # Third positional argument
#default values (in case user doesn't supply them)
if (is.na(my_var_1)) my_var_1 <- "default_1"
if (is.na(my_var_2)) my_var_2 <- "default_2"
if (is.na(my_var_3)) my_var_3 <- "default_3"
print(paste0("1st command line argument is ", my_var_1))
print(paste0("2nd command line argument is ", my_var_2))
print(paste0("3rd command line argument is ", my_var_3))