Skip to content

Commit

Permalink
Add a check for memory-request validity
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-Eagles committed Sep 28, 2023
1 parent 2c29601 commit 5597cd7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions R/job_single.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,19 @@ job_single <- function(name, create_shell = FALSE, partition = "shared", memory
stop("'logdir' has to be a relative path.")
}

## Check the validity of core and memory requests
if (cores < 1) {
stop("'cores' should be at least 1", call. = FALSE)
}
cores <- as.integer(cores)

if (!grepl('^[1-9][0-9]*[KMGT]$', memory)) {
stop(
"Could not parse memory request. Must be a character containing a positive integer and units 'K', 'M', 'G', or 'T'.",
call. = FALSE
)
}

## Specify the array options if a task number was specified
array_spec <- if (!is.null(task_num)) {
paste0("#SBATCH --array=1-", task_num, "%", tc, "\n")
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-job_single.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ test_that("job_single", {
expect_error(run_test(email = "hello"), "'email' should be one of")
expect_error(run_test(logdir = "/logs"), "relative path")
expect_error(run_test(cores = 0.5), "should be at least 1")
expect_error(run_test(memory = 10), "invalid memory request")
expect_error(run_test(memory = "5GB"), "invalid memory request")
expect_error(run_test(memory = 10), "Could not parse memory request")
expect_error(run_test(memory = "5GB"), "Could not parse memory request")
run_test()
expect_error(run_test(delete = FALSE, create_shell = TRUE), "already exists!")
})

0 comments on commit 5597cd7

Please sign in to comment.