Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plot.mhmm uses global variables instead of variables passed into function if interactive = TRUE #39

Closed
grahamammal opened this issue Jun 10, 2019 · 0 comments

Comments

@grahamammal
Copy link

While using the CRAN version of this package, if a call to the function plot.mhmm happens with interactive = TRUE is wrapped inside of a function, plot.mhmm looks for global variables for its input instead of the local variables in the function scope. Trying to use variables in the function scope results in the following error:

For example, running:

obs <- seqdef(sapply(1:10, function(i){
  rbinom(10, 2, prob=c(.5, .5))
}))


plot_wrapper <- function(wrapped_model) { 
  plot(wrapped_model, interactive = FALSE)
}          

plot_wrapper(fit_model(build_mmm(obs, n_clusters = 2))$model)

causes the following error:

9.
(function (x, which.plots = NULL, nrow = NA, ncol = NA, byrow = FALSE, 
    row.prop = "auto", col.prop = "auto", layout = "horizontal", 
    pie = TRUE, vertex.size = 40, vertex.label = "initial.probs", 
    vertex.label.dist = "auto", vertex.label.pos = "bottom",  ... 
8.
do.call(mHMMplotgrid, args) 
7.
plot.mhmm(wrapped_model, interactive = FALSE) 
6.
plot(wrapped_model, interactive = FALSE) at .active-rstudio-document#7
5.
plot_wrapper(fit_model(build_mmm(obs, n_clusters = 2))$model) at .active-rstudio-document#10
4.
eval(ei, envir) 
3.
eval(ei, envir) 
2.
withVisible(eval(ei, envir)) 
1.
source("~/.active-rstudio-document", echo = TRUE) 

However if we assign the input of the function to be a global variable, like this instead:

obs <- seqdef(sapply(1:10, function(i){
  rbinom(10, 2, prob=c(.5, .5))
}))


plot_wrapper <- function(wrapped_model) {
  temp <<- wrapped_model
  plot(temp, interactive = FALSE)
}          

plot_wrapper(fit_model(build_mmm(obs, n_clusters = 2))$model)

We get no error.

@helske helske closed this as completed in 9e85e2b Jun 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant