Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- setwd("~")
- pkgs <- c("stringr", "plyr", "dplyr", "reshape2",
- "parallel", "snow", "ggplot2")
- sapply(pkgs, library, character.only = TRUE, quietly = TRUE)
- used_cores <- detectCores(logical = FALSE)
- cluster <- makePSOCKcluster(used_cores)
- clusterExport(cluster, "pkgs")
- clusterEvalQ(cluster, sapply(pkgs, require, character.only = TRUE))
- eg <- function(nm) {
- x <- rnorm(100)
- df <- ldply(c(0.1, 0.5, 1), function(bw) {
- data.frame(bw,
- getAnywhere(bin)[which(getAnywhere(bin)$where ==
- "namespace:ggplot2")](x, binwidth = bw))
- })
- tryCatch({tmp <- ggplot(df) +
- geom_histogram(aes(x, y = density, width = width), stat = "identity") +
- facet_wrap(~bw)
- ggsave(paste0(nm, ".png"), tmp)
- })
- }
- parLapplyLB(cluster, 1:10000, eg)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement