## Define parameters as separate vectors. X_vector <- 1:4 Y_vector <- c("A", "B", "C") ## In this example there are 12 possible combinations ## and therefore 12 tasks that need to be run. ## Use expand.grid to generate all possible parameter combinations param_grid <- expand.grid(X = X_vector, Y = Y_vector) ## expand.grid returns a dataframe. In this example it returns 12 rows, which ## matches the expected 12 tasks we will need to run. ## Next we need the $SGE_TASK_ID argument from the command line. ## Get the argument that was passed via command line. argv <- commandArgs(TRUE) if (length(argv) > 0){ # In this example $SGE_TASK_ID is the first argument # located at index of 1 (e.g. argv[1]) # Save the $SGE_TASK_ID value to 'task_ID' variable task_ID <- as.numeric( argv[1] ) } ## Learn more about the $SGE_TASK_ID argument in file "param_sweep.qsub" ## Consider each row of the 'param_grid' dataframe as a task number. ## We then use the 'task_ID' value as a row index to extract ## the parameters to be used for this task run. X <- param_grid[task_ID,]$X Y <- param_grid[task_ID,]$Y ## Run your analysis print(paste("Task ID:", task_ID)) print(paste("Parameter 1:", X)) print(paste("Parameter 2:", Y))