From 0ae774b7f033f32233be4d8edfcca0d0ffb91266 Mon Sep 17 00:00:00 2001 From: Markus Kainu Date: Mon, 26 Aug 2024 11:04:41 +0300 Subject: [PATCH] Added an alternative way to download files directly from Avoin data --- DESCRIPTION | 6 +++--- NAMESPACE | 2 ++ R/onAttach.R | 5 +++++ R/read_data.R | 23 +++++++++++++++++++++++ man/get_data_csv.Rd | 17 +++++++++++++++++ 5 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 R/onAttach.R create mode 100644 man/get_data_csv.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 24de2f9..75a8447 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: kelaopendata Type: Package Title: Access open data from National social insurance institution of Finland -Version: 0.1.0002 -Date: 2024-06-06 +Version: 0.1.1 +Date: 2024-08-26 Author: Markus Kainu Maintainer: Markus Kainu Description: Designed to simplify and speed up access to open data from National social insurance institution of Finland (KELA) published at , the kelaopendata package offers researchers and analysts a set of tools to obtain data and metadata for a wide range of applications. @@ -21,4 +21,4 @@ Imports: glue Encoding: UTF-8 LazyData: true -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 diff --git a/NAMESPACE b/NAMESPACE index 71327ce..14aa2d2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,6 +2,7 @@ export(get_csv_links) export(get_data) +export(get_data_csv) export(get_metadata) export(list_ckan) export(list_datasets) @@ -20,3 +21,4 @@ importFrom(dplyr,filter) importFrom(dplyr,mutate) importFrom(glue,glue) importFrom(jsonlite,fromJSON) +importFrom(readr,read_csv) diff --git a/R/onAttach.R b/R/onAttach.R new file mode 100644 index 0000000..37c9dfb --- /dev/null +++ b/R/onAttach.R @@ -0,0 +1,5 @@ +.onAttach <- function(lib, pkg) { + packageStartupMessage(paste0("kelaopendata ", + utils::packageVersion("kelaopendata"), + ": Access open data from Kela.\nhttps://github.com/ropengov/kelaopendata\nData is licensed under CC-BY 4.0. Please give appropriate attribution to Kela when using data.")) +} diff --git a/R/read_data.R b/R/read_data.R index 6fb74ef..376d5be 100644 --- a/R/read_data.R +++ b/R/read_data.R @@ -34,6 +34,29 @@ get_data <- function(data_id, sql = NA){ } +#' Download the whole data set using csv-files +#' +#' @param data_id data id +#' +#' @return tibble +#' @export +#' +#' @importFrom readr read_csv +#' @importFrom dplyr as_tibble +#' @importFrom dplyr %>% +#' +get_data_csv <- function(data_id){ + + pkg_lst <- pick_a_pkg(input_dataset = data_id) + + csv_links <- get_csv_links(pkg_lst = pkg_lst) + + flst <- lapply(csv_links, readr::read_csv) + res <- do.call('rbind', flst) |> as_tibble() + return(res) +} + + diff --git a/man/get_data_csv.Rd b/man/get_data_csv.Rd new file mode 100644 index 0000000..a790d56 --- /dev/null +++ b/man/get_data_csv.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/read_data.R +\name{get_data_csv} +\alias{get_data_csv} +\title{Download the whole data set using csv-files} +\usage{ +get_data_csv(data_id) +} +\arguments{ +\item{data_id}{data id} +} +\value{ +tibble +} +\description{ +Download the whole data set using csv-files +}