knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

kthapi

Lifecycle: experimental R-CMD-check R-CMD-check

The goal of the kthapi R package is to provide an API wrapper for some of the APIs used at KTH, The Royal Institute of Technology, which can be used directly in R.

The KTH APIs are described here:

https://www.kth.se/api/anvand-data-fran-kth-1.57059

The KTH APIs provide information about employee profiles, published web content, places, course schemas and program catalogues. This R package interfaces with the API, making data available to use directly from R.

Installation

You can install the development version of kthapi from GitHub with:

#install.packages("devtools)
devtools::install_github("KTH-Library/kthapi", dependencies = TRUE)

Example usage

This API wrapper / client is pre-configured with a set of API endpoints:

library(kthapi)
library(knitr)
suppressPackageStartupMessages(library(dplyr))

This is a basic example which shows you how to make a lookup using the v 1.1 "legacy" Profiles API, where we get contact information for a KTH employee using an account name:

profile <- 
  kth_profile_legacy("tjep") %>% 
  .$content 

# inspect this record
profile %>% glimpse()

# pivot into long format and display as a table
profile %>% t() %>% as.data.frame() %>%  
  cbind(rownames(.)) %>% setNames(nm = c("value", "key")) %>% as_tibble() %>%
  select(key, value) %>%
  kable()


# NB: some valid account names do not return data
tryCatch(kth_profile_legacy("markussk"), error = function(e) e)

More examples

This is a basic example which shows how to make a lookup using the authenticated Profiles API:

profile <- 
  kth_profile(username = "tjep") %>%
  .$content

# organizational belonging
profile$worksFor$items %>% 
  tibble::as_tibble() %>%
  select(path, name, nameEn) %>%
  knitr::kable()

# corresponding "slugs"
profile$worksFor$items$path

# displayname used in ABM app
kth_displayname("tjep", type = "username")

# NB: this (authenticated API call) does not throw an error for non-employees
kth_displayname("markussk", type = "username")

For more usage examples, please see the package vignettes.



KTH-Library/kthapi documentation built on June 27, 2023, 9:27 p.m.