This example shows how to use the kth_school_dep()
function to enumerate some organizational unit "slugs".
For these slugs, associated KTH employees with the word "HEAD" in their titles are listed.
This creates a list of potentially responsible heads for this set of organizational units at KTH.
For most units there are several potential matches.
library(kthapi) library(dplyr) library(stringr) library(purrr) #> #> Attaching package: 'purrr' #> The following object is masked from 'package:kthapi': #> #> flatten #> The following object is masked from 'package:testthat': #> #> is_null library(tibble) # some slugs of relevance slugs <- kth_school_dep() %>% # we look for schools (ie slugs containing a slash character) mutate(is_dep = stringr::str_detect(slug, "/")) %>% # we exclude t, vg, zaa and m/m slugs () mutate(is_excluded = stringr::str_detect(slug, "t/|vg/|zaa/|m/m")) %>% # retain just the deps and non-excluded slugs filter(is_dep, !is_excluded) %>% pull(slug) slugs <- setNames(nm = slugs) # a function to flag potential heads (containing the word HEAD in the english descr) dep_heads <- function(slug) kth_catalog(slug = slug)$users %>% mutate(is_head = grepl("HEAD", `title.en`)) %>% filter(is_head) # iterate over all slugs to locate potential heads potential_heads <- slugs %>% purrr::map_dfr(dep_heads, .id = "slug") # display some of the results display <- potential_heads %>% select(slug, username, title = `title.en`) %>% inner_join(kth_school_dep()) %>% select(slug, slug_id = kthid, desc = `description.en`, username, title) #> Joining, by = "slug" display <- display %>% slice(sample(nrow(display), size = 5)) knitr::kable(display)
|slug |slug_id |desc |username |title | |:-----|:--------|:--------------------------------------------------------------|:--------|:------------------------------| |j/jr |u22y13wv |DEPARTMENT OF INTELLIGENT SYSTEMS |mikaelj |PROF., DEPUTY HEAD OF DIVISION | |c/cg |u2hmae9o |DEPARTMENT OF FIBRE AND POLYMER TECHNOLOGY |monicaek |PROFESSOR, HEAD OF DIVISION | |a/al |u23cj6w6 |SUSTAINABLE DEVELOPMENT, ENVIRONMENTAL SCIENCE AND ENGINEERING |malmstro |HEAD OF DEPARTMENT, ASSOC.PROF | |j/jj |u24u5kih |DEPARTMENT OF ELECTRICAL ENERGY ENGINEERING |mnorgren |PROFESSOR, HEAD OF DIVISION | |a/aab |u2zd9bd6 |SCHOOLS OFFICE OF STUDENT AFFAIRS ABE |tiinav |HEAD OF STUDENT COUNSELOR |
# for each potential head, additional info can be looked up, like this: kth_profile_legacy(display$username[1])$content %>% select(url, worksfor = `worksFor.url`) %>% glimpse() #> Rows: 1 #> Columns: 2 #> $ url <chr> "https://www.kth.se/profile/mikaelj" #> $ worksfor <chr> "https://www.kth.se/directory/j/jr/jrl"
What divisions (KTH -> School -> Department (sv: Institution) -> Division (sv: Avdelning)) are there?
# get some relevant schools and departments ksd <- kth_school_dep() %>% mutate(is_excluded = ifelse(nchar(stringr::str_match(slug, "t|vg|zaa")) > 0, TRUE, FALSE)) %>% # retain just the deps and non-excluded slugs filter(is.na(is_excluded)) %>% arrange(-desc(slug)) %>% select(slug, desc = `description.en`) knitr::kable(ksd %>% slice(1:5))
|slug |desc | |:-----|:------------------------------------------------| |a |SCHOOL OF ARCHITECTURE AND THE BUILT ENVIRONMENT | |a/aaa |SCHOOLS OFFICE | |a/aab |SCHOOLS OFFICE OF STUDENT AFFAIRS ABE | |a/abe |ABE SKOLAN | |a/acp |VIABLE CITIES |
# use one of the slugs ai <- kth_catalog(slug = "a/ai") # users can now be enumerated, for example: #knitr::kable(ai$users %>% slice(1:5)) # divisions can be enumerated for each of the departments, for example: ai$catalog %>% select(slug, `description.en`, kthid) %>% knitr::kable()
|slug |description.en |kthid | |:--------|:------------------------------------------------------|:--------| |a/ai/aia |DIVISION OF REAL ESTATE AND CONSTRUCTION MANAGEMENT |u2n3dep0 | |a/ai/aib |DIVISION OF REAL ESTATE ECONOMICS AND FINANCE |u2vce7hj | |a/ai/aic |DIVISION OF REAL ESTATE PLANNING AND LAND LAW |u2yhezo5 | |a/ai/aid |DIVISION OF CONSTRUCTION AND FACILITIES MANAGEMENT |u2ctw8g8 | |a/ai/aie |DIVISION OF REAL ESTATE BUSINESS AND FINANCIAL SYSTEMS |u21evul2 | |a/ai/aig |DIVISION OF GEODESY AND SATELLITE POSITIONING |u21ttfwm |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.