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.

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.


# 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)

# my google scholar user id from my profile url
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)) %>%
#    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", "<b>T Hackl</b>") # make my name fat
  ) %>% split(.$year) %>%
      x <- x %>%
        glue_data('<tr><td width="450">{author} ({year}) <a href="{cid}&btnI=1&hl=en">{title}</a>, {journal}, {number}</td></tr>') %>%
        str_replace_all("(, )+</p>", "</p>") %>%
      x <- c('<table class="publication-table" border="10px solid blue" cellspacing="0" cellpadding="6" rules="", frame=""><tbody>', x, '</tbody></table>')
    }) %>% rev

html_3 <- map2(names(html_2) %>% paste0("<h3>", ., "</h3>"), html_2, c) %>% unlist

html_4 <- c(
  paste0('<p style="text-align: right; margin-top: -40px;"><small>Last updated <i>',
         format(Sys.Date(), format="%B %d, %Y"),
         '– Pulled automatically from my <a href="">Google Scholar profile</a>. See <a href="">this post</a> for how it works.</small></p>'), 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. 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.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)