Skip to content

Recycling trajectory issues when using 'now' function #301

Answered by Enchufa2
chrisreading01 asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, functions in trajectories are tied to the environment where the trajectory was defined, and there's also some cleaning involved to avoid reference loops that could make your memory grow indefinitely.

A simple solution to your third example would be something like this:

sim3 <- NULL # <---
t3 <- trajectory() %>% 
  timeout(1) %>% 
  log_(function(){as.character(simmer::now(sim3))})

runASim2 <- function(traj){
  sim3 <<- simmer() # <---
  sim3 %>% 
    add_generator("test",traj,at(0,1,2,3,4)) %>% 
    run()
} 

runASim2(t3)

Note that the first line is not strictly needed, but it helps if you define the trajectory in another place different from the global environment. The best solutio…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@chrisreading01
Comment options

@Enchufa2
Comment options

@chrisreading01
Comment options

@Enchufa2
Comment options

Answer selected by Enchufa2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants