Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup #6

Merged
merged 4 commits into from Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Expand Up @@ -11,6 +11,8 @@ on:
pull_request:
branches:
- main
schedule:
- cron: "30 12 * * 3"

name: R-CMD-check

Expand Down Expand Up @@ -52,6 +54,17 @@ jobs:

- uses: r-lib/actions/setup-pandoc@v1

- name: "[Custom block] [macOS] Install libraries"
if: runner.os == 'macOS'
run: |
# conflicts with gfortran from r-lib/actions when linking gcc
# rm '/usr/local/bin/gfortran'
# brew install udunits
brew install pkg-config gdal proj geos udunits
- name: "[Stage] [Linux] Install required system libs"
if: runner.os == 'Linux'
run: sudo apt install libcurl4-openssl-dev libgit2-dev proj-bin

- name: Query dependencies
run: |
install.packages('remotes')
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
@@ -1,7 +1,7 @@
Package: tongfen
Type: Package
Title: Make Data Based on Different Geographies Comparable
Version: 0.3.2
Version: 0.3.3
Authors@R: c(
person("Jens", "von Bergmann", email = "jens@mountainmath.ca", role = c("aut", "cre"), comment = "creator and maintainer"))
Description: Several functions to allow comparisons of data across different geographies, in particular for Canadian census data from different censuses.
Expand Down
23 changes: 22 additions & 1 deletion R/tongfen.R
Expand Up @@ -51,6 +51,19 @@ meta_for_additive_variables <- function(dataset,variables){
#' result <- tongfen_estimate(geo2 %>% rename(Population_2016=Population),geo1,meta)
#'}
tongfen_estimate <- function(target,source,meta,na.rm=FALSE) {
# make sure we only have polygon type geomtries
target_geo_types <- target %>% sf::st_geometry_type() %>% unique
source_geo_types <- source %>% sf::st_geometry_type() %>% unique
if (length(setdiff(target_geo_types,c("MULTIPOLYGON","POLYGON")))>0) {
warning(paste0("Target geometry has to be of type POLYGON or MULTIPOLYGON, but given target has types ",
paste0(target_geo_types,collapse=", "),". Dropping other geometries."))
target <- target %>% sf::st_collection_extract("POLYGON")
}
if (length(setdiff(source_geo_types,c("MULTIPOLYGON","POLYGON")))>0) {
warning(paste0("SOURCE geometry has to be of type POLYGON or MULTIPOLYGON, but given SOURCE has types ",
paste0(source_geo_types,collapse=", "),". Dropping other geometries."))
source <- source %>% sf::st_collection_extract("POLYGON")
}

unique_key="tongfen_row_number"
target <- target %>% mutate(!!unique_key:=row_number())
Expand Down Expand Up @@ -331,7 +344,15 @@ tongfen_aggregate <- function(data,correspondence,meta=NULL, base_geo = NULL){
if (!is.null(meta)) {
d <- d %>% aggregate_data_with_meta(meta)
} else {
d <- d %>% summarize()
if ("sf" %in% class(d)) {
geo_column=attr(d,"sf_column")
d <- d %>% summarize(!!geo_column:=suppressMessages(sf::st_union(!!as.name(geo_column))) %>%
sf::st_cast("MULTIPOLYGON"),
.groups="drop")

} else {
d <- d %>% summarize(.groups="drop")
}
}
}) %>%
setNames(nn)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -85,7 +85,7 @@ Methods to facilitate this are still under active development.
If you wish to cite tongfen:

von Bergmann, J. (2021). tongfen: R package to
Make Data Based on Different Geographies Comparable. v0.3.2.
Make Data Based on Different Geographies Comparable. v0.3.3.


A BibTeX entry for LaTeX users is
Expand All @@ -94,7 +94,7 @@ A BibTeX entry for LaTeX users is
author = {Jens {von Bergmann}},
title = {tongfen: R package to Make Data Based on Different Geographies Comparable},
year = {2021},
note = {R package version 0.3.2},
note = {R package version 0.3.3},
url = {https://mountainmath.github.io/tongfen/},
}
```
2 changes: 1 addition & 1 deletion docs/404.html

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

2 changes: 1 addition & 1 deletion docs/LICENSE-text.html

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

2 changes: 1 addition & 1 deletion docs/LICENSE.html

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

2 changes: 1 addition & 1 deletion docs/articles/index.html

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

6 changes: 3 additions & 3 deletions docs/articles/polling_districts.html

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

@@ -0,0 +1,12 @@
// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
// be compatible with the behavior of Pandoc < 2.8).
document.addEventListener('DOMContentLoaded', function(e) {
var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
var i, h, a;
for (i = 0; i < hs.length; i++) {
h = hs[i];
if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
a = h.attributes;
while (a.length > 0) h.removeAttribute(a[0].name);
}
});
4 changes: 2 additions & 2 deletions docs/articles/tongfen-ca-estimate.html

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

@@ -0,0 +1,12 @@
// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
// be compatible with the behavior of Pandoc < 2.8).
document.addEventListener('DOMContentLoaded', function(e) {
var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
var i, h, a;
for (i = 0; i < hs.length; i++) {
h = hs[i];
if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
a = h.attributes;
while (a.length > 0) h.removeAttribute(a[0].name);
}
});
16 changes: 13 additions & 3 deletions docs/articles/tongfen.html

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

6 changes: 3 additions & 3 deletions docs/articles/tongfen_ca.html

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

12 changes: 12 additions & 0 deletions docs/articles/tongfen_ca_files/header-attrs-2.8/header-attrs.js
@@ -0,0 +1,12 @@
// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
// be compatible with the behavior of Pandoc < 2.8).
document.addEventListener('DOMContentLoaded', function(e) {
var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
var i, h, a;
for (i = 0; i < hs.length; i++) {
h = hs[i];
if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
a = h.attributes;
while (a.length > 0) h.removeAttribute(a[0].name);
}
});
12 changes: 12 additions & 0 deletions docs/articles/tongfen_files/header-attrs-2.8/header-attrs.js
@@ -0,0 +1,12 @@
// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
// be compatible with the behavior of Pandoc < 2.8).
document.addEventListener('DOMContentLoaded', function(e) {
var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
var i, h, a;
for (i = 0; i < hs.length; i++) {
h = hs[i];
if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
a = h.attributes;
while (a.length > 0) h.removeAttribute(a[0].name);
}
});
4 changes: 2 additions & 2 deletions docs/articles/tongfen_us.html

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

12 changes: 12 additions & 0 deletions docs/articles/tongfen_us_files/header-attrs-2.8/header-attrs.js
@@ -0,0 +1,12 @@
// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
// be compatible with the behavior of Pandoc < 2.8).
document.addEventListener('DOMContentLoaded', function(e) {
var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
var i, h, a;
for (i = 0; i < hs.length; i++) {
h = hs[i];
if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
a = h.attributes;
while (a.length > 0) h.removeAttribute(a[0].name);
}
});
2 changes: 1 addition & 1 deletion docs/authors.html

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