Skip to content

Instantly share code, notes, and snippets.

@yeedle
Forked from hadley/tiobe.R
Last active January 12, 2018 15:47
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 yeedle/ee067a85f6727733643f30f73ee53849 to your computer and use it in GitHub Desktop.
Save yeedle/ee067a85f6727733643f30f73ee53849 to your computer and use it in GitHub Desktop.
library(rvest)
library(stringr)
library(tidyverse)
page <- read_html("https://www.tiobe.com/tiobe-index/r/")
script <- page %>%
html_node("body > section > section > section > article > script") %>%
html_text()
script %>% str_replace_all("\n|\r", " ") %>%
str_extract("\\[\\[.*\\]\\]") %>%
str_replace_all("Date.UTC\\(([0-9]+), ([0-9]+), ([0-9]+)\\)", '"\\1-\\2-\\3"') %>%
jsonlite::fromJSON() %>%
as_tibble() %>%
separate(V1, into = c("year", "month", "day"), sep = "-") %>%
mutate(date = as.Date(paste0(year, "-", as.numeric(month)+1, "-", day))) %>%
select(date, value = V2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment