Skip to content

Commit

Permalink
Merge pull request #203 from mrc-ide/fix-partial-names
Browse files Browse the repository at this point in the history
Allow only some processes to be named and not others.
  • Loading branch information
plietar authored Aug 13, 2024
2 parents 76496ec + fe41a9e commit 079e45e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/simulation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test-simulation-e2e.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})

0 comments on commit 079e45e

Please sign in to comment.