Skip to content

Commit

Permalink
Fix get_municipalities function argument, update datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
pitkant committed Oct 20, 2023
1 parent 175ae40 commit 2d66ff0
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 8 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: sorvi
Type: Package
Title: Functions for Finnish Open Data
Version: 0.8.21
Date: 2023-08-21
Date: 2023-10-20
Authors@R: c(
person("Leo", "Lahti", , "leo.lahti@iki.fi", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-5537-637X")),
Expand All @@ -20,7 +20,7 @@ URL: https://github.com/ropengov/sorvi,
https://CRAN.R-project.org/package=sorvi,
https://ropengov.github.io/sorvi/
Depends:
R (>= 3.5.0)
R (>= 3.6.0)
Imports:
dlstats,
dplyr,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ importFrom(rlang,.data)
importFrom(rvest,html_elements)
importFrom(rvest,html_text)
importFrom(sf,st_as_sf)
importFrom(sf,st_drop_geometry)
importFrom(sf,st_is_empty)
importFrom(tidyr,tibble)
importFrom(utils,read.csv)
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# sorvi 0.8.22 (2023-10-20)

### BUG FIXES

- Fixed function argument `type` in `get_municipalities()` - now it actually affects the class of the returned object! New default object type is `sf` and other options are `tibble` and `data.frame`
- Fixed Loimaan mlk / Loimaa lk and Metsämaa division / merger information in the datasets `sorvi::kunnat1865_2021` and `sorvi::polygons1909_2009`

# sorvi 0.8.21 (2023-08-21)

### NEW FEATURES
Expand Down
14 changes: 10 additions & 4 deletions R/select_municipalities_by_year.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
#' pick a certain year and return an output that contains the most recent
#' information on each municipality.
#' @param year a year between 1865-2020
#' @param type either "data.frame" or "sf"
#' @param type either "data.frame", "tibble" or "sf"
#' @return a data.frame or sf object
#' @details See dataset "kunnat1865_2021"
#' @importFrom dplyr group_by arrange filter left_join
#' @importFrom magrittr %>%
#' @importFrom checkmate assert_integer assert_choice
#' @importFrom sf st_is_empty st_as_sf
#' @importFrom sf st_is_empty st_as_sf st_drop_geometry
#' @source Data attribution: FinnONTO Consortium: \url{https://seco.cs.aalto.fi/projects/finnonto/}
#' @export
#' @author Pyry Kantanen
get_municipalities <- function(year = 2002, type = "data.frame") {
get_municipalities <- function(year = 2002, type = "sf") {
checkmate::assert_double(year, lower = 1865, upper = 2020)
checkmate::assert_choice(type, choices = c("data.frame", "sf"))
checkmate::assert_choice(type, choices = c("data.frame", "tibble", "sf"))

kunnat1865_2021 <- sorvi::kunnat1865_2021
polygons1909_2009 <- sorvi::polygons1909_2009
Expand Down Expand Up @@ -48,6 +48,12 @@ get_municipalities <- function(year = 2002, type = "data.frame") {
}
}

if (type == "data.frame") {
filtered_dataset <- sf::st_drop_geometry(filtered_dataset)
filtered_dataset <- as.data.frame(filtered_dataset)
} else if (type == "tibble") {
filtered_dataset <- sf::st_drop_geometry(filtered_dataset)
}

return(filtered_dataset)
}
Binary file modified data/kunnat1865_2021.rda
Binary file not shown.
Binary file modified data/polygons1909_2009.rda
Binary file not shown.
4 changes: 2 additions & 2 deletions man/get_municipalities.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2d66ff0

Please sign in to comment.