Skip to content

Commit 92cf1e0

Browse files
apply indentation_linter
1 parent 1afb7ea commit 92cf1e0

9 files changed

Lines changed: 284 additions & 169 deletions

File tree

.lintr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ linters: linters_with_defaults(
1111
expect_true_false_linter(),
1212
expect_type_linter(),
1313
implicit_integer_linter(allow_colon = TRUE),
14+
indentation_linter(hanging_indent_style = "never"),
1415
infix_spaces_linter(exclude_operators = c("=", "*", "/")),
1516
line_length_linter(120),
1617
quotes_linter("'"),
@@ -20,6 +21,5 @@ linters: linters_with_defaults(
2021
)),
2122
assignment_linter = NULL,
2223
commented_code_linter = NULL,
23-
indentation_linter = NULL,
2424
object_name_linter = NULL
2525
)

R/gh_decode.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
gh_decode = function(geohashes, include_delta = FALSE, coord_loc = 'c') {
22
if (is.factor(geohashes)) {
3-
return(lapply(gh_decode(levels(geohashes), include_delta, coord_loc),
4-
function(z) z[geohashes]))
3+
return(lapply(
4+
gh_decode(levels(geohashes), include_delta, coord_loc),
5+
function(z) z[geohashes]
6+
))
57
}
68
if (length(coord_loc) > 1L)
79
stop("Please provide only one value for 'coord_loc'")
@@ -16,8 +18,7 @@ gh_decode = function(geohashes, include_delta = FALSE, coord_loc = 'c') {
1618
'northwest' = , 'nw' = 6L,
1719
'north' = , 'n' = 7L,
1820
'northeast' = , 'ne' = 8L,
19-
stop('Unrecognized coordinate location; please use ',
20-
"'c' for centroid or a cardinal direction; see ?gh_decode")
21+
stop("Unrecognized coordinate location; please use 'c' for centroid or a cardinal direction; see ?gh_decode")
2122
)
2223
.Call(Cgh_decode, geohashes, include_delta, coord_loc)
2324
}

R/gh_encode.R

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
gh_encode = function(latitude, longitude, precision = 6L) {
22
if (length(precision) != 1L)
33
stop('More than one precision value detected; precision is fixed on input (for now)')
4-
if (precision < 1L) stop('Invalid precision. Precision is measured in ',
5-
'number of characters, must be at least 1.')
4+
if (precision < 1L)
5+
stop('Invalid precision. Precision is measured in number of characters, must be at least 1.')
66
if (precision > .global$GH_MAX_PRECISION) {
7-
warning('Precision is limited to ', .global$GH_MAX_PRECISION,
8-
' characters; truncating')
7+
warning('Precision is limited to ', .global$GH_MAX_PRECISION, ' characters; truncating')
98
precision = .global$GH_MAX_PRECISION
109
}
1110

R/gis_tools.R

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ wgs = function() sp::CRS('+proj=longlat +datum=WGS84', doCheckCRSArgs = FALSE)
44
# nocov start
55
check_suggested = function(pkg) {
66
if (!requireNamespace(pkg, quietly = TRUE)) {
7-
stop('This function requires an installation of ', pkg,
8-
"; install.packages('", pkg, "') to proceed.")
7+
stop('This function requires an installation of ', pkg, "; install.packages('", pkg, "') to proceed.")
98
}
109
}
1110
# nocov end
@@ -48,8 +47,7 @@ gh_to_spdf.default = function(geohashes, ...) {
4847

4948
gh_to_spdf.data.frame = function(gh_df, gh_col = 'gh', ...) {
5049
if (is.na(idx <- match(gh_col, names(gh_df))))
51-
stop('Searched for geohashes at a column named "',
52-
gh_col, '", but found nothing.')
50+
stop('Searched for geohashes at a column named "', gh_col, '", but found nothing.')
5351
gh = gh_df[[idx]]
5452
if (anyDuplicated(gh) > 0L) {
5553
idx = which(duplicated(gh))

tests/testthat/test-decode.R

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ test_that('geohash decoder works', {
131131
tolerance = 1e-8
132132
)
133133
# be sure adjacent geohashes interlock
134-
expect_identical(lapply(c('nw', 'n', 'ne'),
135-
function(l) gh_decode('m', coord_loc = l)),
136-
lapply(c('sw', 's', 'se'),
137-
function(l) gh_decode('t', coord_loc = l)))
134+
expect_identical(
135+
lapply(c('nw', 'n', 'ne'), function(l) gh_decode('m', coord_loc = l)),
136+
lapply(c('sw', 's', 'se'), function(l) gh_decode('t', coord_loc = l))
137+
)
138138

139139
expect_error(
140140
gh_decode(c(borobudur, neum), coord_loc = c('n', 's')),
@@ -148,28 +148,43 @@ test_that('geohash decoder works', {
148148
)
149149

150150
# invalid geohash characters:
151-
expect_error(gh_decode('a'), fixed = TRUE,
152-
"Invalid geohash; check 'a' at index 1.")
153-
expect_error(gh_decode(c('b', 'a')), fixed = TRUE,
154-
"Invalid geohash; check 'a' at index 2.")
151+
expect_error(
152+
gh_decode('a'),
153+
"Invalid geohash; check 'a' at index 1.",
154+
fixed = TRUE
155+
)
156+
expect_error(
157+
gh_decode(c('b', 'a')),
158+
"Invalid geohash; check 'a' at index 2.",
159+
fixed = TRUE
160+
)
155161

156162
# missing input
157-
expect_identical(gh_decode(c(neum, NA_character_)),
158-
list(latitude = c(42.91259765625, NA),
159-
longitude = c(17.60009765625, NA)))
160-
expect_identical(gh_decode(c(neum, NA_character_), include_delta = TRUE),
161-
list(latitude = c(42.91259765625, NA),
162-
longitude = c(17.60009765625, NA),
163-
delta_latitude = c(0.02197265625, NA),
164-
delta_longitude = c(0.02197265625, NA)))
163+
expect_identical(
164+
gh_decode(c(neum, NA_character_)),
165+
list(latitude = c(42.91259765625, NA), longitude = c(17.60009765625, NA))
166+
)
167+
expect_identical(
168+
gh_decode(c(neum, NA_character_), include_delta = TRUE),
169+
list(
170+
latitude = c(42.91259765625, NA),
171+
longitude = c(17.60009765625, NA),
172+
delta_latitude = c(0.02197265625, NA),
173+
delta_longitude = c(0.02197265625, NA)
174+
)
175+
)
165176

166177
# stress testing
167178
## empty input
168-
expect_identical(gh_decode(character(0L)),
169-
list(latitude = numeric(0L), longitude = numeric(0L)))
179+
expect_identical(
180+
gh_decode(character(0L)),
181+
list(latitude = numeric(0L), longitude = numeric(0L))
182+
)
170183
## !nzchar input
171-
expect_identical(gh_decode(''),
172-
list(latitude = NA_real_, longitude = NA_real_))
184+
expect_identical(
185+
gh_decode(''),
186+
list(latitude = NA_real_, longitude = NA_real_)
187+
)
173188
## long input [intr_length > 8 in geohash_decode_impl]
174189
expect_identical(
175190
gh_decode(strrep('1', 26L)),
@@ -181,7 +196,9 @@ test_that('geohash decoder works', {
181196
## useBytes needed a bit strangely -- that the error returns with _any_
182197
## non-ASCII character throws off the string matching even when only
183198
## attempting to match ASCII-only characters.
184-
expect_error(gh_decode(rawToChar(as.raw(128L))),
185-
fixed = TRUE, useBytes = TRUE,
186-
'Non-ASCII character at index 1')
199+
expect_error(
200+
gh_decode(rawToChar(as.raw(128L))),
201+
'Non-ASCII character at index 1',
202+
fixed = TRUE, useBytes = TRUE
203+
)
187204
})

tests/testthat/test-encode.R

Lines changed: 53 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,16 @@ test_that('geohash encoder works', {
99
expect_identical(gh_encode(y, x), gh_encode(y, x - 360.0))
1010

1111
# all level-1 centroids to be sure my manual logic for precision = 1 works
12-
expect_identical(gh_encode(c(-67.5, -67.5, -22.5, -22.5, -67.5, -67.5, -22.5,
13-
-22.5, 22.5, 22.5, 67.5, 67.5, 22.5, 22.5, 67.5,
14-
67.5, -67.5, -67.5, -22.5, -22.5, -67.5, -67.5,
15-
-22.5, -22.5, 22.5, 22.5, 67.5, 67.5, 22.5, 22.5,
16-
67.5, 67.5),
17-
c(-157.5, -112.5, -157.5, -112.5, -67.5, -22.5,
18-
-67.5, -22.5, -157.5, -112.5, -157.5, -112.5,
19-
-67.5, -22.5, -67.5, -22.5, 22.5, 67.5, 22.5,
20-
67.5, 112.5, 157.5, 112.5, 157.5, 22.5, 67.5,
21-
22.5, 67.5, 112.5, 157.5, 112.5, 157.5),
22-
precision = 1L),
23-
c('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'b', 'c',
24-
'd', 'e', 'f', 'g', 'h', 'j', 'k', 'm', 'n', 'p', 'q', 'r',
25-
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'))
12+
# nolint start: line_length_linter.
13+
expect_identical(
14+
gh_encode(
15+
c(-067.5, -67.5, -22.5, -22.5, -67.5, -67.5, -22.5, -22.5, 22.5, 22.5, 67.5, 67.5, 22.5, 22.5, 67.5, 67.5, -67.5, -67.5, -22.5, -22.5, -67.5, -67.5, -22.5, -22.5, 22.5, 22.5, 67.5, 67.5, 22.5, 22.5, 67.5, 67.5),
16+
c(-157.5, -112.5, -157.5, -112.5, -67.5, -22.5, -67.5, -22.5, -157.5, -112.5, -157.5, -112.5, -67.5, -22.5, -67.5, -22.5, 22.5, 67.5, 22.5, 67.5, 112.5, 157.5, 112.5, 157.5, 22.5, 67.5, 22.5, 67.5, 112.5, 157.5, 112.5, 157.5),
17+
precision = 1L
18+
),
19+
c('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z')
20+
)
21+
# nolint end: line_length_linter.
2622

2723
# geohash cells are _left closed, right open_: [x1, x2) x [y1, y2), see:
2824
# http://geohash.org/s000
@@ -31,23 +27,31 @@ test_that('geohash encoder works', {
3127
# boundary cases
3228
# need to balloon eps so that adding .5 doesn't obliterate sig figs
3329
eps = 1000.0*.Machine$double.eps
34-
expect_identical(gh_encode(c(eps, eps, -eps, -eps,
35-
90.0 - eps, 90.0 - eps, eps - 90.0, eps - 90.0),
36-
c(eps, -eps, eps, -eps,
37-
eps - 180.0, 180.0 - eps, eps - 180.0, 180.0 - eps)),
38-
c('s00000', 'ebpbpb', 'kpbpbp', '7zzzzz',
39-
'bpbpbp', 'zzzzzz', '000000', 'pbpbpb'))
30+
expect_identical(
31+
gh_encode(
32+
c(eps, eps, -eps, -eps, 90.0 - eps, 90.0 - eps, eps - 90.0, eps - 90.0),
33+
c(eps, -eps, eps, -eps, eps - 180.0, 180.0 - eps, eps - 180.0, 180.0 - eps)
34+
),
35+
c('s00000', 'ebpbpb', 'kpbpbp', '7zzzzz', 'bpbpbp', 'zzzzzz', '000000', 'pbpbpb')
36+
)
4037

4138
# test precision argument
4239
expect_identical(gh_encode(y, x, 12L), 's0h09nrnzgqv')
4340
# maximum precision
4441
n = 25L
45-
expect_identical(gh_encode(y, x, n),
46-
substring('s0h09nrnzgqv8je0f4jpd0000', 1L, n))
42+
expect_identical(
43+
gh_encode(y, x, n),
44+
substring('s0h09nrnzgqv8je0f4jpd0000', 1L, n)
45+
)
4746
# truncation beyond there
48-
expect_warning(out <- gh_encode(y, x, n + 5L),
49-
'Precision is limited', fixed = TRUE)
50-
expect_identical(out, substring('s0h09nrnzgqv8je0f4jpd0000', 1L, n))
47+
expect_warning(
48+
expect_identical(
49+
gh_encode(y, x, n + 5L),
50+
substring('s0h09nrnzgqv8je0f4jpd0000', 1L, n)
51+
),
52+
'Precision is limited',
53+
fixed = TRUE
54+
)
5155

5256
# implicit integer truncation
5357
expect_identical(gh_encode(y, x, 1.04), 's')
@@ -58,25 +62,39 @@ test_that('geohash encoder works', {
5862
# invalid input
5963
expect_error(gh_encode(100.0, x), 'Invalid latitude at index 1', fixed = TRUE)
6064
expect_error(gh_encode(-91.0, x), 'Invalid latitude at index 1', fixed = TRUE)
61-
expect_error(gh_encode(c(y, 90.0), c(x, x)),
62-
'Invalid latitude at index 2', fixed = TRUE)
63-
expect_error(gh_encode(y, x, c(5L, 6L)),
64-
'More than one precision value', fixed = TRUE)
65-
expect_error(gh_encode(c(y, y), x),
66-
'Inputs must be the same size', fixed = TRUE)
65+
expect_error(
66+
gh_encode(c(y, 90.0), c(x, x)),
67+
'Invalid latitude at index 2',
68+
fixed = TRUE
69+
)
70+
expect_error(
71+
gh_encode(y, x, c(5L, 6L)),
72+
'More than one precision value',
73+
fixed = TRUE
74+
)
75+
expect_error(
76+
gh_encode(c(y, y), x),
77+
'Inputs must be the same size',
78+
fixed = TRUE
79+
)
6780

6881
# semi-valid auto-corrected input -- 180 --> -180 by wrapping
6982
expect_identical(gh_encode(y, 180.0), '80008n')
7083
expect_identical(gh_encode(y, 293475908.0), 'db508w')
7184

7285
# missing/infinite input
7386
expect_identical(gh_encode(c(y, NA), c(x, NA)), c('s0h09n', NA_character_))
74-
expect_identical(gh_encode(c(NaN, Inf, -Inf, 1:3), c(1:3, NaN, Inf, -Inf)),
75-
rep(NA_character_, 6L))
87+
expect_identical(
88+
gh_encode(c(NaN, Inf, -Inf, 1:3), c(1:3, NaN, Inf, -Inf)),
89+
rep(NA_character_, 6L)
90+
)
7691

7792
# different branch for precision=1 of the above errors
78-
expect_error(gh_encode(100.0, x, 1L),
79-
'Invalid latitude at index 1', fixed = TRUE)
93+
expect_error(
94+
gh_encode(100.0, x, 1L),
95+
'Invalid latitude at index 1',
96+
fixed = TRUE
97+
)
8098
expect_identical(gh_encode(y, 180.0, 1L), '8')
8199
expect_identical(gh_encode(NA, NA, 1L), NA_character_)
82100

0 commit comments

Comments
 (0)