Skip to content

Commit

Permalink
Description and few other things
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Kainu committed Jun 6, 2024
1 parent 268ea3a commit 00e9ed9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 53 deletions.
9 changes: 4 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
Package: kelaopendata
Type: Package
Title: What the Package Does (Title Case)
Version: 0.1.0001
Date: 2024-04-12
Title: Access open data by National social insurance institution of Finland
Version: 0.1.0002
Date: 2024-06-06
Author: Markus Kainu
Maintainer: Markus Kainu <markus.kainu@kapsi.fi>
Description: More about what it does (maybe more than one line)
Use four spaces when indenting paragraphs within the Description.
Description: Designed to simplify and speed up access to open data from National social insurance institution of Finland (KELA) published at <https://www.avoindata.fi/data/fi/organization/kela>, the kelaopendata package offers researchers and analysts a set of tools to obtain data and metadata for a wide range of applications.
License: Artistic-2.0 | file LICENSE
URL: https://ropengov.github.io/kelaopendata/, https://github.com/rOpenGov/kelaopendata
BugReports: https://github.com/rOpenGov/kelaopendata/issues
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ importFrom(DBI,dbGetQuery)
importFrom(ckanr,ckanr_setup)
importFrom(ckanr,package_search)
importFrom(dplyr,"%>%")
importFrom(dplyr,arrange)
importFrom(dplyr,as_tibble)
importFrom(dplyr,bind_rows)
importFrom(dplyr,filter)
importFrom(dplyr,mutate)
importFrom(glue,glue)
importFrom(jsonlite,fromJSON)
11 changes: 7 additions & 4 deletions R/ckan.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ list_ckan <- function(org = "Kansaneläkelaitos", n = 100){
#'
#' @return data.frame
#'
#' @importFrom dplyr bind_rows
#' @importFrom dplyr bind_rows arrange mutate
#'
#' @export
#'
Expand All @@ -57,12 +57,15 @@ list_datasets <- function(){
for (i in seq(dsets$results)){
tmp <- dsets$results[i]
dlist[[i]] <- data.frame(
modified = tmp[[1]]$metadata_modified,
name = tmp[[1]]$name,
id = tmp[[1]]$id,
modified = tmp[[1]]$metadata_modified
id = tmp[[1]]$id
)
}
res <- do.call("bind_rows", dlist) %>% as_tibble()
res <- do.call("bind_rows", dlist) %>%
as_tibble() %>%
mutate(modified = as.Date(modified)) %>%
arrange(desc(modified))
return(res)
}

Expand Down
44 changes: 4 additions & 40 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,54 +14,18 @@ Install
remotes::install_github("rOpenGov/kelaopendata")
```



## List datasets

```{r}
library(kelaopendata)
dsets <- list_datasets()
dsets
```

## Metadata

Get metadata

```{r}
meta <- get_metadata(data_id = dsets$id[1])
meta[1:4]
```


Resources

```{r}
jsonlite::toJSON(meta$resources, pretty = T)
print(dsets, n = 50)
```


## Download data

Get first 10 rows of data

```{r}
get_data(data_id = dsets$id[1], sql = "LIMIT 10")
```


Whole dataset

```{r}
whole_data <- get_data(data_id = dsets$id[1])
whole_data
```


Subset only men from municipality Veteli from year 2023
Download the first 10 rows of the most recently modified data

```{r}
veteli23 <- get_data(data_id = dsets$id[1], sql = "WHERE kunta_nro = 924 AND vuosi = 2023 AND sukupuoli = 'Mies'")
veteli23
first_ten_rows <- get_data(data_id = dsets$id[1], sql = "LIMIT 10")
first_ten_rows
```

9 changes: 5 additions & 4 deletions vignettes/read_data.Rmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Reading data using kelaopendata"
title: "Fetching data using kelaopendata"
author: "Markus Kainu"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
Expand Down Expand Up @@ -66,18 +66,19 @@ First 10 rows

```{r}
get_data(data_id = id_opintotuki, sql = "LIMIT 10")
dat <- get_data(data_id = id_opintotuki)
```

Filter using SQL

```{r}
yliopistot <- get_data(data_id = id_opintotuki,
sql = "WHERE kunta_nro = 853 AND
aikatyyppi = 'Kuukausi' AND
etuus = 'Opintolainan valtiontakaus' AND
aikatyyppi = 'Vuosi' AND
etuus = 'Yhteensä' AND
oppilaitos_peruste = 'Viimeisin oppilaitos' AND
oppilaitosaste = 'Yliopistot'")
yliopistot
yliopistot %>% count(vuosi)
```

Plot
Expand Down

0 comments on commit 00e9ed9

Please sign in to comment.