knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(Lab5RT)
Kolada is a collaboration between the Swedish state, Swedish regions and the municipalities in Sweden. The service is ran by non-profit Rådet för främjande av Kommunala Analyser (RKA). The service is provided to make it easier to evaluate and perform analysis of the services that the regions and municipalites provide. The database kolada contains the statistics of services.
The package contains five functions, four which are read only and a fifth that retrieves the specified data from the database.
get_kpi is a read function used to search for different Key Performance Indicators (KPI) and retrieves the specified key which can be used later on for retrieving data. To use the function input a keyword in string form for example "skola". The function will output the first 15 results that contain the keyword. The output returned is of the class kolada.
get_kpi("skola") # Over 15 matches found. Number of matches found: 533 # KPI: N00022 # Explanation: Kostnadsutj.netto: förskola och skolbarnsomsorg, kr/inv 1 nov fg år # # KPI: N00023 # Explanation: Kostnadsutj.netto: Grundskola, kr/inv. 1 nov fg år # # KPI: N00026 # Explanation: Kostnadsutj.netto: Gymnasieskolan, kr/inv 1 nov fg år # # KPI: N00108 # Explanation: Månadsavlönad personal, kommunalt anställda i förskola, skola, fritids m.m., antal # # KPI: N00114 # Explanation: Årsarbetare, kommunalt anställda i förskola, skola, fritids m.m., antal # # KPI: N03165 # Explanation: Investeringsutgifter inom förskola, fritidshem och annan pedagogisk verksamhet kommun, kr/inv) (-2017) # # . ... # . # . ... # # # KPI: N09891 # Explanation: Flickor i kulturskolan, 6-19 år, andel (%)
Another example of a even more general search.
get_kpi("a") # Over 100 matches found. Number of matches found: 4858 # KPI: N00002 # Explanation: Personalkostnader som andel av verksamhetens kostnader, andel (%) # # KPI: N00003 # Explanation: Personalkostnader, kr/inv # # KPI: N00005 # Explanation: Utjämningssystemet enl resultaträkning, kr/inv # # . ... # . # . ... # # # KPI: N00026 # Explanation: Kostnadsutj.netto: Gymnasieskolan, kr/inv 1 nov fg år
The function get_ou() is used to retrieve read information from the database about organizational unit and has the same structure as get_kpi. Where the user input a search string into the function and it prints the first 15 results. The description and kpi for the first 15 organizations found. It returns a object of the class kolada.
get_ou("norrland") # KPI: V25E3004 # Explanation: Norrlandsgatans gruppbostad # # KPI: V25E4756 # Explanation: Norrlandsgatans serviceboende # # KPI: V30E7289 # Explanation: Norrlandsgatan 6A (AoB) # # KPI: V60E64001 # Explanation: Norrlands universitetssjukhus, Umeå (fastigheter) # # KPI: V70E64001 # Explanation: Norrlands Universitetssjukhus, Umeå # # KPI: V70E99022 # Explanation: Övriga sjukhus/kliniker Västernorrlands län # # KPI: V70U6400101 # Explanation: Norrlands Universitetssjukhus, Umeå IVA
The function get_municipality has the same structure the previous functions, it takes a search string for a municipality in Sweden. Then it prints municipalities KPI for the selected municipality. It returns a object of the class kolada.
get_municipality("um") # KPI: 1764 # Explanation: Grums # # KPI: 1881 # Explanation: Kumla # # KPI: 1441 # Explanation: Lerum # # KPI: 2421 # Explanation: Storuman # # KPI: 1435 # Explanation: Tanum # # KPI: 2480 # Explanation: Umeå
The heart of the read functions is get_kolada_obj which is called by each and everyone of the read functions, the inputs are in string format where it searches the database and returns a object of the kolada class. For the get_kolada_obj function the first input is the search string and the second specifies what kind of search it is. Its recommended to use one of the other read functions since they are easier to use, because in the second input either "kpi", "municipality" or "ou" must be specified. It then follows the structure of the previous read functions.
#How they must be specified get_kolada_obj("a", "kpi") get_kolada_obj("a", "municipality") get_kolada_obj("a", "ou")
The get_data function is a get function that takes the data from the database. With the kpi keys from previous read functions it's possible to withdraw the data and outputs a tibble. The function takes three inputs, get_kpi() kpi and get_municipality() kpi and the year for which we are interested in. The input needs to be in string format.
The following code uses the output from previous read functions.
get_data("N00022", "2480", "2010" ) # A tibble: 1 x 7 # kpi municipality period count gender status value # <chr> <chr> <int> <int> <chr> <chr> <dbl> # 1 N00022 2480 2010 1 T "" -94
It is also possible to choose include more than one kpi for search string for each input, if separated with a comma in the string.
get_data("N00002,N00003,N00005", "1280", "2010,2011,2012" ) # A tibble: 9 x 7 # kpi municipality period count gender status value # <chr> <chr> <int> <int> <chr> <chr> <dbl> # 1 N00002 1280 2010 1 T "" 52.0 # 2 N00002 1280 2011 1 T "" 52.3 # 3 N00002 1280 2012 1 T "" 52.8 # 4 N00003 1280 2010 1 T "" 26359. # 5 N00003 1280 2011 1 T "Missing" NA # 6 N00003 1280 2012 1 T "" 28267. # 7 N00005 1280 2010 1 T "" 12563. # 8 N00005 1280 2011 1 T "" 12356. # 9 N00005 1280 2012 1 T "" 12074.
By omiting for example year input we recieve the information for every year, where we can see that it withdrew all 66 rows.
get_data("N00002,N00003,N00005", "1280" ) # A tibble: 66 x 7 # kpi municipality period count gender status value # <chr> <chr> <int> <int> <chr> <chr> <dbl> # 1 N00002 1280 1998 1 T "" 60.0 # 2 N00002 1280 1999 1 T "" 50 # 3 N00002 1280 2000 1 T "" 51.0 # 4 N00002 1280 2001 1 T "" 52.0 # 5 N00002 1280 2002 1 T "" 53.1 # 6 N00002 1280 2003 1 T "" 54.0 # 7 N00002 1280 2004 1 T "" 54.0 # 8 N00002 1280 2005 1 T "" 54.0 # 9 N00002 1280 2006 1 T "" 55.0 # 10 N00002 1280 2007 1 T "" 55.1 # # ... with 56 more rows
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.