From 5597cd72ca55e9f66a74f424ff642b1d6e9a76d9 Mon Sep 17 00:00:00 2001 From: Nick-Eagles Date: Thu, 28 Sep 2023 11:59:20 -0400 Subject: [PATCH] Add a check for memory-request validity --- R/job_single.R | 8 ++++++++ tests/testthat/test-job_single.R | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/R/job_single.R b/R/job_single.R index fb6dfd7..0d12bf4 100644 --- a/R/job_single.R +++ b/R/job_single.R @@ -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") diff --git a/tests/testthat/test-job_single.R b/tests/testthat/test-job_single.R index 50d6cfb..f2d217b 100644 --- a/tests/testthat/test-job_single.R +++ b/tests/testthat/test-job_single.R @@ -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!") })