Last active
September 1, 2017 06:43
-
-
Save bedantaguru/1004cd27774436ca334ee0d44569d918 to your computer and use it in GitHub Desktop.
Defining Variable in R Package Environment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
progress_print <- function(){ | |
L <- list(init = function(x) {M <<- x}, step = function() NULL, term = function() NULL) | |
itr <- 0 | |
M <- 1 | |
L$step <- function(){ | |
itr <<- itr + 1 | |
cat(paste0("Job ", itr, " out of ", M, "\n")) | |
} | |
return(L) | |
} | |
# this will give error | |
assign("progress_print", value = progress_print, envir = environment(llply)) | |
# so we have to do like this | |
environment(progress_print) <- environment(llply) | |
# here is one usage of above | |
ldply(seq(10), function(i) data.frame(x = rnorm(1), y = rnorm(1)), .progress = "print") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment