Automatically update your publication list using R scholar
[This article was first published on Thomas Hackl | Coding Biologist, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
I really dislike tedious tasks like updating my publication list on my
website. So here is a very short script that does the job for me. It uses the R
library scholar to pull my publications from my google scholar profile. I then
use some quick & dirty string parsing to convert that data into a html
table. I’m sure there are a tons of more elegant ways out there, but this
worked, and only took me minutes to set up.
library(scholar) library(tidyverse) library(glue) # escape some special chars, german umlauts, ... char2html <- function(x){ dictionary <- data.frame( symbol = c("ä","ö","ü","Ä", "Ö", "Ü", "ß"), html = c("ä","ö", "ü","Ä", "Ö", "Ü","ß")) for(i in 1:dim(dictionary)[1]){ x <- gsub(dictionary$symbol[i],dictionary$html[i],x) } x } # my google scholar user id from my profile url # https://scholar.google.com/citations?user=b8bWNkUAAAAJ&hl=en thackl <- "b8bWNkUAAAAJ" # pull from google html_1 <- get_publications(thackl) # convert to htlm table - the ugly way ;) html_2 <- html_1 %>% as_tibble %>% arrange(desc(year)) %>% mutate( # author=str_replace_all(author, " (\\S) ", "\\1 "), author=str_replace_all(author, "([A-Z]) ([A-Z]) ", "\\1\\2 "), author=str_replace_all(author, ", \\.\\.\\.", " et al."), author=str_replace_all(author, "T Hackl", "T Hackl") # make my name fat ) %>% split(.$year) %>% map(function(x){ x <- x %>% glue_data('') %>% str_replace_all("(, )+", "") %>% char2html() x <- c(' {author} ({year}) {title}, {journal}, {number}
", ., "
"), html_2, c) %>% unlist html_4 <- c( paste0('Last updated ', format(Sys.Date(), format="%B %d, %Y"), '– Pulled automatically from my Google Scholar profile. See this post for how it works.
'), html_3) # write the html list to a file writeLines(html_4, "../_includes/publications.html")To leave a comment for the author, please follow the link and comment on their blog: Thomas Hackl | Coding Biologist.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.