Skip to content

Commit 5bea8d2

Browse files
committed
Merge branch 'ateucher-issue170-mixed-logical'
2 parents 5875b42 + 9e2a80f commit 5bea8d2

File tree

6 files changed

+88
-102
lines changed

6 files changed

+88
-102
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 25 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
2+
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
13
on:
24
push:
3-
branches:
4-
- master
5+
branches: [main, master]
56
pull_request:
6-
branches:
7-
- master
87

9-
name: R-CMD-check
8+
name: R-CMD-check.yaml
9+
10+
permissions: read-all
1011

1112
jobs:
1213
R-CMD-check:
@@ -18,65 +19,33 @@ jobs:
1819
fail-fast: false
1920
matrix:
2021
config:
21-
- {os: windows-latest, r: '3.6'}
22-
- {os: macOS-latest, r: '3.6'}
23-
- {os: macOS-latest, r: 'devel'}
24-
- {os: ubuntu-16.04, r: '3.3', rspm: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"}
25-
- {os: ubuntu-16.04, r: '3.4', rspm: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"}
26-
- {os: ubuntu-16.04, r: '3.5', rspm: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"}
27-
- {os: ubuntu-16.04, r: '3.6', rspm: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"}
22+
- {os: macos-latest, r: 'release'}
23+
- {os: windows-latest, r: 'release'}
24+
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
25+
- {os: ubuntu-latest, r: 'release'}
26+
- {os: ubuntu-latest, r: 'oldrel-1'}
2827

2928
env:
30-
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
31-
RSPM: ${{ matrix.config.rspm }}
29+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
30+
R_KEEP_PKG_SOURCE: yes
3231

3332
steps:
34-
- uses: actions/checkout@v2
33+
- uses: actions/checkout@v4
34+
35+
- uses: r-lib/actions/setup-pandoc@v2
3536

36-
- uses: r-lib/actions/setup-r@master
37+
- uses: r-lib/actions/setup-r@v2
3738
with:
3839
r-version: ${{ matrix.config.r }}
40+
http-user-agent: ${{ matrix.config.http-user-agent }}
41+
use-public-rspm: true
3942

40-
- uses: r-lib/actions/setup-pandoc@master
41-
42-
- name: Query dependencies
43-
run: |
44-
install.packages('remotes')
45-
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
46-
shell: Rscript {0}
47-
48-
- name: Cache R packages
49-
if: runner.os != 'Windows'
50-
uses: actions/cache@v1
43+
- uses: r-lib/actions/setup-r-dependencies@v2
5144
with:
52-
path: ${{ env.R_LIBS_USER }}
53-
key: ${{ runner.os }}-r-${{ matrix.config.r }}-${{ hashFiles('.github/depends.Rds') }}
54-
restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}-
55-
56-
- name: Install system dependencies
57-
if: runner.os == 'Linux'
58-
env:
59-
RHUB_PLATFORM: linux-x86_64-ubuntu-gcc
60-
run: |
61-
Rscript -e "remotes::install_github('r-hub/sysreqs')"
62-
sysreqs=$(Rscript -e "cat(sysreqs::sysreq_commands('DESCRIPTION'))")
63-
sudo -s eval "$sysreqs"
64-
65-
- name: Install dependencies
66-
run: |
67-
remotes::install_deps(dependencies = TRUE)
68-
remotes::install_cran("rcmdcheck")
69-
shell: Rscript {0}
70-
71-
- name: Check
72-
env:
73-
_R_CHECK_CRAN_INCOMING_REMOTE_: false
74-
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
75-
shell: Rscript {0}
45+
extra-packages: any::rcmdcheck
46+
needs: check
7647

77-
- name: Upload check results
78-
if: failure()
79-
uses: actions/upload-artifact@master
48+
- uses: r-lib/actions/check-r-package@v2
8049
with:
81-
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
82-
path: check
50+
upload-snapshots: true
51+
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'

DESCRIPTION

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Title: GeoJSON to Simple Feature Converter
44
Version: 2.0.5
55
Date: 2024-07-30
66
Authors@R: c(
7-
person("David", "Cooley", ,"dcooley@symbolix.com.au", role = c("aut", "cre"))
7+
person("David", "Cooley", ,"dcooley@symbolix.com.au", role = c("aut", "cre")),
8+
person("Andy", "Teucher", ,"andy.teucher@gmail.com", role = "ctb")
89
)
910
Description: Converts Between GeoJSON and simple feature objects.
1011
License: MIT + file LICENSE
@@ -21,16 +22,15 @@ LinkingTo:
2122
sfheaders (>= 0.4.5)
2223
Imports:
2324
Rcpp
24-
RoxygenNote: 7.1.0
25+
RoxygenNote: 7.3.3
2526
Suggests:
2627
covr,
27-
jsonify,
28+
jsonify (>= 1.2.3),
2829
knitr,
2930
rmarkdown,
3031
tinytest
3132
VignetteBuilder: knitr
32-
remotes:
33-
https://github.com/dcooley/sfheaders,
34-
https://github.com/SymbolixAU/jsonify,
35-
https://github.com/SymbolixAU/rapidjsonr
36-
33+
Remotes:
34+
dcooley/sfheaders,
35+
SymbolixAU/jsonify,
36+
SymbolixAU/rapidjsonr

README.Rmd

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ knitr::opts_chunk$set(
1717
![downloads](http://cranlogs.r-pkg.org/badges/grand-total/geojsonsf)
1818
[![CRAN RStudio mirror downloads](http://cranlogs.r-pkg.org/badges/geojsonsf)](https://CRAN.R-project.org/package=geojsonsf)
1919
[![Github Stars](https://img.shields.io/github/stars/SymbolixAU/geojsonsf.svg?style=social&label=Github)](https://github.com/SymbolixAU/geojsonsf)
20-
[![R build status](https://github.com/symbolixau/geojsonsf/workflows/R-CMD-check/badge.svg)](https://github.com/symbolixau/geojsonsf/actions)
20+
[![R-CMD-check](https://github.com/SymbolixAU/geojsonsf/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/SymbolixAU/geojsonsf/actions/workflows/R-CMD-check.yaml)
2121
[![Coverage Status](https://codecov.io/github/SymbolixAU/geojsonsf/coverage.svg?branch=master)](https://codecov.io/github/SymbolixAU/geojsonsf?branch=master)
2222

2323
--
@@ -176,7 +176,3 @@ microbenchmark(
176176
# geojsonsf 709.2268 709.2268 722.0626 722.0626 734.8984 734.8984 2
177177
# sf 1867.6840 1867.6840 1958.7968 1958.7968 2049.9097 2049.9097 2
178178
```
179-
180-
181-
182-

README.md

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
geojsonsf
22
================
33

4-
[![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/geojsonsf)](https://CRAN.R-project.org/package=geojsonsf)
4+
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/geojsonsf)](https://CRAN.R-project.org/package=geojsonsf)
55
![downloads](http://cranlogs.r-pkg.org/badges/grand-total/geojsonsf)
66
[![CRAN RStudio mirror
77
downloads](http://cranlogs.r-pkg.org/badges/geojsonsf)](https://CRAN.R-project.org/package=geojsonsf)
88
[![Github
99
Stars](https://img.shields.io/github/stars/SymbolixAU/geojsonsf.svg?style=social&label=Github)](https://github.com/SymbolixAU/geojsonsf)
10-
[![R build
11-
status](https://github.com/symbolixau/geojsonsf/workflows/R-CMD-check/badge.svg)](https://github.com/symbolixau/geojsonsf/actions)
10+
[![R-CMD-check](https://github.com/SymbolixAU/geojsonsf/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/SymbolixAU/geojsonsf/actions/workflows/R-CMD-check.yaml)
1211
[![Coverage
1312
Status](https://codecov.io/github/SymbolixAU/geojsonsf/coverage.svg?branch=master)](https://codecov.io/github/SymbolixAU/geojsonsf?branch=master)
1413

@@ -19,18 +18,18 @@ Status](https://codecov.io/github/SymbolixAU/geojsonsf/coverage.svg?branch=maste
1918
A simple, low-dependency and **fast** converter between GeoJSON and
2019
Simple Feature objects in R.
2120

22-
-----
21+
------------------------------------------------------------------------
2322

2423
**v1.3.2**
2524

2625
Converts
2726

28-
- GeoJSON –\> `sf`
29-
- GeoJSON –\> `sfc`
30-
- `sf`\> GeoJSON
31-
- `sfc`\> GeoJSON
32-
- GeoJSON –\> Well-known text
33-
- data.frame –\> GeoJSON (POINT only)
27+
- GeoJSON –\> `sf`
28+
- GeoJSON –\> `sfc`
29+
- `sf`\> GeoJSON
30+
- `sfc`\> GeoJSON
31+
- GeoJSON –\> Well-known text
32+
- data.frame –\> GeoJSON (POINT only)
3433

3534
As per GeoJSON ([RFC 7946
3635
specification)](https://tools.ietf.org/html/rfc7946#page-11), foreign
@@ -96,12 +95,10 @@ js <- c(
9695
sf <- geojson_sf( js )
9796
sf
9897
# Simple feature collection with 3 features and 1 field
99-
# geometry type: GEOMETRY
100-
# dimension: XY
101-
# bbox: xmin: -1 ymin: -1 xmax: 100 ymax: 1
102-
# z_range: zmin: NA zmax: NA
103-
# m_range: mmin: NA mmax: NA
104-
# CRS: 4326
98+
# Geometry type: GEOMETRY
99+
# Dimension: XY
100+
# Bounding box: xmin: -1 ymin: -1 xmax: 100 ymax: 1
101+
# Geodetic CRS: WGS 84
105102
# id geometry
106103
# 1 NA POINT (0 0)
107104
# 2 NA LINESTRING (-1 -1, 1 1)

inst/include/geojsonsf/geojson/geojson_properties.hpp

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,14 @@ namespace geojson_properties {
5252
} else if (existing_type != "Null" && existing_type != type && type != "Null") {
5353

5454
// allow NULL through so the type is correct when back in R
55-
// if it's different, update to be a 'String'
56-
property_types[property] = "String";
55+
// Treat "True" and "False" as the same type (logical)
56+
bool both_logical = (existing_type == "True" || existing_type == "False") &&
57+
(type == "True" || type == "False");
58+
59+
if (!both_logical) {
60+
// if it's different, update to be a 'String'
61+
property_types[property] = "String";
62+
}
5763

5864
} else if (existing_type == "Null") {
5965
// If the first element is NULL, use the new type
@@ -246,21 +252,10 @@ namespace geojson_properties {
246252
update_numeric_vector(properties, key, value, row_index-1);
247253
}
248254

249-
} else if (value_type == "False") {
250-
251-
bool this_value = p.value.GetBool();
252-
if (type != "False") {
253-
std::string value = any_to_string(this_value);
254-
update_string_vector(properties, key, value, row_index-1);
255-
} else {
256-
bool value = p.value.GetBool();
257-
update_logical_vector(properties, key, value, row_index-1);
258-
}
259-
260-
} else if (value_type == "True") {
255+
} else if (value_type == "False" || value_type == "True") {
261256

262257
bool this_value = p.value.GetBool();
263-
if (type != "True") {
258+
if (type != "True" && type != "False") {
264259
std::string value = any_to_string(this_value);
265260
update_string_vector(properties, key, value, row_index-1);
266261
} else {
@@ -292,5 +287,3 @@ namespace geojson_properties {
292287
} // namespace geojsonsf
293288

294289
#endif
295-
296-

inst/tinytest/test-geojson_sf.R

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,34 @@
100100
out <- geojson_sf( geojson )
101101
expect_equal(out[1][[1]], "Münster")
102102
expect_equal(names(out)[1], "örtchen")
103+
104+
## Issue 170
105+
## Logicals correctly converted
106+
gj <- '{"type":"FeatureCollection","features":[
107+
{"type":"Feature","properties":{"a":true},"geometry":{"type":"Point","coordinates":[0.0,0.0]}},
108+
{"type":"Feature","properties":{"a":false},"geometry":{"type":"Point","coordinates":[1.0,1.0]}},
109+
{"type":"Feature","properties":{"a":false},"geometry":{"type":"Point","coordinates":[2.0,2.0]}},
110+
{"type":"Feature","properties":{"a":true},"geometry":{"type":"Point","coordinates":[3.0,3.0]}}
111+
]}'
112+
113+
sf <- geojson_sf(gj)
114+
expect_true(is.logical(sf$a))
115+
expect_equal(sf$a, c(TRUE, FALSE, FALSE, TRUE))
116+
117+
## works with all false
118+
gj <- '{"type":"FeatureCollection","features":[
119+
{"type":"Feature","properties":{"a":false},"geometry":{"type":"Point","coordinates":[0.0,0.0]}},
120+
{"type":"Feature","properties":{"a":false},"geometry":{"type":"Point","coordinates":[1.0,1.0]}}
121+
]}'
122+
123+
sf <- geojson_sf(gj)
124+
expect_true(is.logical(sf$a))
125+
126+
## works with all true
127+
gj <- '{"type":"FeatureCollection","features":[
128+
{"type":"Feature","properties":{"a":true},"geometry":{"type":"Point","coordinates":[0.0,0.0]}},
129+
{"type":"Feature","properties":{"a":true},"geometry":{"type":"Point","coordinates":[1.0,1.0]}}
130+
]}'
131+
132+
sf <- geojson_sf(gj)
133+
expect_true(is.logical(sf$a))

0 commit comments

Comments
 (0)