Skip to content

Instantly share code, notes, and snippets.

@njahn82
Created August 23, 2017 15:52
Show Gist options
  • Select an option

  • Save njahn82/f8a58da2ccea95c4505556e315c2709b to your computer and use it in GitHub Desktop.

Select an option

Save njahn82/f8a58da2ccea95c4505556e315c2709b to your computer and use it in GitHub Desktop.
pub test
#' ## What's registered in PUB?
#'
#' ### Fetch the data
#'
orgs <- rio::import("pevz_org.csv") %>%
mutate(year = list(2009:2016)) %>%
tidyr::unnest(year)
u <- "https://pub.uni-bielefeld.de/publication?limit=1000&q="
tt <- purrr::map2(.x = orgs$id, .y= orgs$year, .f = function(x, y) {
my_url <- URLencode(paste0(u, "department=", x, " AND year=", y, "&fmt=json"))
jsonlite::fromJSON(my_url)
})
# listen benennen
names(tt) <- orgs$id
# data frame aus listenelementen gewinnen
my_data <- map_df(tt, `[`, c("year", "_id", "type"), .id = "org")
# externe publikationen herausnehmen
ext_ids <- filings %>%
select(`_id`, extern) %>%
filter(!is.na(extern)) %>%
.$`_id`
my_data_unibi <- my_data %>%
filter(!`_id` %in% ext_ids)
# backup
rio::export(my_data, "counts_bis.csv")
my_counts <- my_data_unibi %>%
group_by(org) %>%
count(year)
# filing siehe unten
my_count_all <- filings %>%
select(`_id`, extern, year) %>%
filter(is.na(extern)) %>%
group_by(year) %>%
summarise(all = n())
my_counts <- my_counts %>%
left_join(my_count_all, by = c("year" = "year")) %>%
mutate(prop = n / all) %>%
filter(!year == 2009)
ggplot(my_count_all, aes(year, all)) + geom_bar(stat = "identity") +facet_wrap(~type)
### by type
my_counts <- my_data_unibi %>%
group_by(type) %>%
count(year)
# filing siehe unten
my_count_all <- filings %>%
select(`_id`, extern, year, type) %>%
filter(is.na(extern)) %>%
group_by(year, type) %>%
summarise(all = n())
## wie kommen wir zu filings
library(jsonlite)
baseurl <- "https://pub.uni-bielefeld.de/publication?limit=1000&q=year%3E=2010%20AND%20year%3C2017&fmt=json"
pages <- list()
for(i in seq(1,, by = 1000)){
mydata <- fromJSON(paste0(baseurl, "&start=", i))
message("Retrieving page ", i)
pages[[i+1]] <- mydata
}
#' combine all into one
filings <- rbind_pages(pages)
#' ### Analyse
library(tidyverse)
filings %>%
group_by(year) %>%
summarise(n())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment