Skip to content

Instantly share code, notes, and snippets.

@JWiley
Created September 17, 2010 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JWiley/584910 to your computer and use it in GitHub Desktop.
Save JWiley/584910 to your computer and use it in GitHub Desktop.
navel.gazer <- function(month = NULL, year = NULL, entire = FALSE,
list = "r-help", n = 50, plot = TRUE) {
# Ben Bolker came up with most of the code
# Henrique Dallazuanna provided an edit to the z <- line of code
# Brian Diggs provided capwords() to properly count Peter Dalgaard
# Joshua Wiley adapted all of it to one function
if(is.null(month)) {
month <- format(Sys.Date(), format = "%B")
}
if(isTRUE(entire)) {
month <- unique(months(as.Date(1:365, "2000-01-01")))
}
if(is.null(year)) {
year <- format(Sys.Date(), format = "%Y")
}
if(length(year) > 1) {
tmp <- vector(mode = "list", length = length(year))
for(i in seq_along(year)) {
tmp[[i]] <- paste(year[i], month, sep = "-")
}
times <- unlist(tmp)
} else {
times <- paste(year, month, sep = "-")
}
require(zoo)
times <- sort(as.yearmon(times, "%Y-%B"))
current <- as.yearmon(Sys.Date(), "%Y-%m")
times <- format(times[times <= current], "%Y-%B")
# Function to extract the names
# Originally by Ben Bolker
namefun <- function(x) {
gsub("\\n","",gsub("^.+<I>","",gsub("</I>.+$","",x)))
}
# Based on a suggestion by Brian Diggs
# Capitalizes the first letter of each word
capwords <- function(s, strict = FALSE) {
cap <- function(s) paste(toupper(substring(s,1,1)),
{s <- substring(s,2); if(strict) tolower(s) else s},
sep = "", collapse = " " )
sapply(strsplit(s, split = " "), cap, USE.NAMES = !is.null(names(s)))
}
# Collects the author names for the relevant month and list
# from the R archives
# Originally by Ben Bolker
grabber <- function(month, list, n) {
baseurl <- "https://stat.ethz.ch/pipermail/"
require(RCurl)
# z <- getURL(paste(baseurl,list,"/",month,"/author.html",sep=""))
z <- getURL(paste(baseurl,list,"/", month,"/author.html",sep=""),
ssl.verifypeer = FALSE)
zz <- strsplit(z,"<LI>")[[1]]
cnames <- capwords(sapply(zz[3:(length(zz)-1)],namefun))
rr <- rev(sort(table(cnames)))
output <- rr[1:n]
return(output)
}
# Create dot plots of the number of posts
# lattice dotplot() code primarily by Ben Bolker
plotter <- function(dat) {
require(lattice)
if(length(dat) > 1) {
old.par <- par(no.readonly = TRUE)
on.exit(par(old.par))
par("ask" = TRUE)
}
for(i in seq_along(dat)) {
print(dotplot(~rev(dat[[i]]), xlab = "Number of posts",
main = names(dat)[i]))
}
invisible()
}
numbers <- lapply(times, function(x)
{grabber(month = x, list = list, n = n)})
names(numbers) <- times
if(plot) {
plotter(dat = numbers)
}
return(numbers)
}
@JWiley
Copy link
Author

JWiley commented Sep 17, 2010

Back in August 2010 on the R-help list, Ben Bolker posted some code to look at a graph of the top 50 posters on the main R-help list for a given month (original thread: http://www.mail-archive.com/r-help@r-project.org/msg106571.html ). I have combined his original code along with a few other recommendations from that thread into one easy function. This function has a number of convenient defaults. If no arguments are passed, it will look up the top 50 authors on the r-help list, for the given month in the given year. You can also specify one or more months as a character vector (e.g., "August" or c("August", "September") ). The same goes for years. You can also choose a different list (such as r-devel).

For those with a lot of time one their hands, you can set argument entire = TRUE, which will look up every month from whatever years you specified (or the current year if you did not). It will return a named list with each element corresponding to one month. Also, by default it will create a dotplot in lattice (though this may be turned off via plot = FALSE). Finally, you can specify how many authors you want. It defaults to 50.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment