Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. setwd("~")
  2.  
  3. pkgs <- c("stringr", "plyr", "dplyr", "reshape2",
  4. "parallel", "snow", "ggplot2")
  5. sapply(pkgs, library, character.only = TRUE, quietly = TRUE)
  6.  
  7. used_cores <- detectCores(logical = FALSE)
  8. cluster <- makePSOCKcluster(used_cores)
  9. clusterExport(cluster, "pkgs")
  10. clusterEvalQ(cluster, sapply(pkgs, require, character.only = TRUE))
  11.  
  12. eg <- function(nm) {
  13. x <- rnorm(100)
  14. df <- ldply(c(0.1, 0.5, 1), function(bw) {
  15. data.frame(bw,
  16. getAnywhere(bin)[which(getAnywhere(bin)$where ==
  17. "namespace:ggplot2")](x, binwidth = bw))
  18. })
  19. tryCatch({tmp <- ggplot(df) +
  20. geom_histogram(aes(x, y = density, width = width), stat = "identity") +
  21. facet_wrap(~bw)
  22. ggsave(paste0(nm, ".png"), tmp)
  23. })
  24. }
  25.  
  26. parLapplyLB(cluster, 1:10000, eg)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement