Last active
May 27, 2019 01:27
-
-
Save johnbaums/560058f7bc2782c8ffbf5eede35ca1fb to your computer and use it in GitHub Desktop.
sapply with progress text (percent complete)
This file contains hidden or 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
pbsapply <- function(x, fun, pass_to, ...) { | |
if(!missing('pass_to')) { | |
call <- sprintf('fun(%s=x[[i]], ...)', pass_to) | |
} else { | |
call <- 'fun(x[[1]], ...) ' | |
} | |
sapply(seq_along(x), function(i) { | |
cat(sprintf('\r%.02f%%', i/length(x)*100)) | |
eval(parse(text=call)) | |
}) | |
} |
Author
johnbaums
commented
May 27, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment