Skip to content

Instantly share code, notes, and snippets.

@mkearney
Created April 21, 2017 15:27
Show Gist options
  • Save mkearney/e1bc65b89cb0c19df17cdba6f6a6a729 to your computer and use it in GitHub Desktop.
Save mkearney/e1bc65b89cb0c19df17cdba6f6a6a729 to your computer and use it in GitHub Desktop.
jlfacts <- function(dir = path.expand("~")) {
if (file.exists(file.path(dir, ".jeffleekfacts.rds"))) {
jlrtfacts <- readRDS(file.path(dir, ".jeffleekfacts.rds"))
} else if ("rtweet" %in% install.packages()) {
jlrt <- rtweet::search_tweets("\"jeff leek\"", n = 500, include_rts = FALSE)
jlrtfacts <- trimws(unique(gsub("@[[:alnum:]_:]+", "", jlrt$text)))
jlrtfacts <- grep("http", jlrtfacts, invert = TRUE, value = TRUE)
saveRDS(jlrtfacts, path.expand(file.path("~", ".jeffleekfacts.rds")))
} else {
jlrtfacts <- "jeff leek doesn't use soap; he uses rm(list = ls())."
}
jlf <- sample(jlrtfacts, 1)
message(jlf)
}
jl <- function(total) {
..ctr.. <- 0
function(expr, value, ok, visible) {
..ctr.. <<- ..ctr.. + 1
active <- (..ctr.. < total)
if (!active) {
message("that's enough about jeff leek")
} else {
jlfacts()
}
active
}
}
addTaskCallback(jl(100), name = "jlfacts")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment