diff --git a/R/simulation.R b/R/simulation.R index 5e05113..7646ab3 100644 --- a/R/simulation.R +++ b/R/simulation.R @@ -212,7 +212,7 @@ prepare_process <- function(p, name = NULL) { ptr <- p p <- function(t) execute_process(ptr, t) } - if (!is.null(name)) { + if (!is.null(name) && name != "") { env <- new.env() assign(name, p, envir=env) p <- function(t) eval(call(name, t), env) diff --git a/tests/testthat/test-simulation-e2e.R b/tests/testthat/test-simulation-e2e.R index fbd1bbd..424a7a5 100644 --- a/tests/testthat/test-simulation-e2e.R +++ b/tests/testthat/test-simulation-e2e.R @@ -172,3 +172,20 @@ test_that("Can give two processes the same name", { expect_equal(names, c("foo", "foo")) }) + +test_that("Can give a name to just one process", { + names <- NULL + + simulation_loop( + processes = list( + function(t) { + names <<- c(names, deparse(sys.call()[[1]])) + }, + foo = function(t) { + names <<- c(names, deparse(sys.call()[[1]])) + } + ), + timesteps = 1) + + expect_equal(names[[2]], "foo") +})