Skip to content

Commit

Permalink
chore: Fix typos and set up lintr (#40)
Browse files Browse the repository at this point in the history
This makes it generally easier to work on in VSCode without a mountain
of blue lintr warnings!
  • Loading branch information
paleolimbot authored May 27, 2024
1 parent feea1a8 commit a6d44ef
Show file tree
Hide file tree
Showing 18 changed files with 105 additions and 60 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
^compile_commands\.json$
^\.cache$
^cran-comments\.md$
^\.lintr$
5 changes: 1 addition & 4 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ jobs:
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: '3.6'}
- {os: windows-latest, r: '4.0'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
Expand All @@ -43,10 +41,9 @@ jobs:

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck, arrow=?ignore-before-r=4.0.0
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
args: 'c("--no-manual", "--as-cran", "--no-multiarch")'
34 changes: 34 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: lint

permissions: read-all

jobs:
lint:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::lintr, local::.
needs: lint

- name: Lint
run: lintr::lint_package()
shell: Rscript {0}
env:
LINTR_ERROR_ON_LINT: true
5 changes: 5 additions & 0 deletions .lintr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
linters: linters_with_defaults(
line_length_linter(90),
commented_code_linter = NULL,
object_name_linter = NULL
)
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: geoarrow
Title: Extension types for geospatial data for use with 'Arrow'
Title: Extension types for spatial data for use with 'Arrow'
Version: 0.1.0.9000
Authors@R:
c(
Expand All @@ -19,8 +19,8 @@ Authors@R:
person("Joao Paulo", "Magalhaes", role = "cph")
)
Description: Provides extension types and conversions to between R-native
object types and 'Arrow' columnar types. This includes integrations among
the 'arrow', 'nanoarrow', 'sf', and 'wk' packages such that geospatial
object types and 'Arrow' columnar types. This includes integration among
the 'arrow', 'nanoarrow', 'sf', and 'wk' packages such that spatial
metadata is preserved wherever possible. Extension type implementations
ensure first-class geometry data type support in the 'arrow' and 'nanoarrow'
packages.
Expand Down
5 changes: 2 additions & 3 deletions R/array.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ as_geoarrow_array.default <- function(x, ..., schema = NULL) {

#' @export
as_geoarrow_array.nanoarrow_array <- function(x, ..., schema = NULL) {
schema_src <- infer_nanoarrow_schema(x)
schema_src <- nanoarrow::infer_nanoarrow_schema(x)
if (is.null(schema)) {
schema <- infer_geoarrow_schema(x)
}
Expand Down Expand Up @@ -316,9 +316,8 @@ force_schema_storage <- function(schema) {
}

force_array_storage <- function(array) {
schema <- force_schema_storage(infer_nanoarrow_schema(array))
schema <- force_schema_storage(nanoarrow::infer_nanoarrow_schema(array))
array_shallow <- nanoarrow::nanoarrow_allocate_array()
nanoarrow::nanoarrow_pointer_export(array, array_shallow)
nanoarrow::nanoarrow_array_set_schema(array_shallow, schema, validate = FALSE)
}

13 changes: 7 additions & 6 deletions R/infer-default.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ infer_geoarrow_schema.default <- function(x, ..., promote_multi = TRUE,

# try vector_meta (doesn't iterate along features)
vector_meta <- wk::wk_vector_meta(x)
all_types <- vector_meta$geometry_type

has_mising_info <- is.na(vector_meta$geometry_type) ||
(vector_meta$geometry_type == 0L) ||
Expand All @@ -45,7 +44,7 @@ infer_geoarrow_schema.default <- function(x, ..., promote_multi = TRUE,
vector_meta$has_z <- any(meta$has_z, na.rm = TRUE)
vector_meta$has_m <- any(meta$has_m, na.rm = TRUE)

schema_from_geometry_types_and_dims(
schema_from_types_and_dims(
x,
unique_types,
has_z = any(meta$has_z, na.rm = TRUE),
Expand All @@ -54,7 +53,7 @@ infer_geoarrow_schema.default <- function(x, ..., promote_multi = TRUE,
coord_type = coord_type
)
} else {
schema_from_geometry_types_and_dims(
schema_from_types_and_dims(
x,
vector_meta$geometry_type,
has_z = vector_meta$has_z,
Expand Down Expand Up @@ -99,7 +98,7 @@ infer_geoarrow_schema.nanoarrow_array_stream <- function(x, ..., promote_multi =
has_z <- any(unique_dims %in% c(2L, 4L))
has_m <- any(unique_dims %in% c(3L, 4L))

schema_from_geometry_types_and_dims(
schema_from_types_and_dims(
x,
unique_types,
has_z,
Expand All @@ -109,8 +108,9 @@ infer_geoarrow_schema.nanoarrow_array_stream <- function(x, ..., promote_multi =
)
}

schema_from_geometry_types_and_dims <- function(x, unique_types, has_z, has_m,
promote_multi, coord_type) {
# nolint start: cyclocomp_linter.
schema_from_types_and_dims <- function(x, unique_types, has_z, has_m,
promote_multi, coord_type) {
if (is.null(coord_type)) {
coord_type <- enum$CoordType$SEPARATE
}
Expand Down Expand Up @@ -149,3 +149,4 @@ schema_from_geometry_types_and_dims <- function(x, unique_types, has_z, has_m,
coord_type = coord_type
)
}
# nolint end
5 changes: 4 additions & 1 deletion R/kernel.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ serialize_kernel_options <- function(vals) {
# When this matters we can wire up nanoarrow's serializer
tmp <- tempfile()
con <- file(tmp, open = "w+b")
on.exit({close(con); unlink(tmp)})
on.exit({
close(con)
unlink(tmp)
})

writeBin(length(vals), con, size = 4L)
for (i in seq_along(vals)) {
Expand Down
20 changes: 10 additions & 10 deletions R/pkg-arrow.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ as_chunked_array.geoarrow_vctr <- function(x, ..., type = NULL) {
schema <- NULL
type <- arrow::as_data_type(attr(x, "schema", exact = TRUE))
} else {
schema <- as_nanoarrow_schema(type)
schema <- nanoarrow::as_nanoarrow_schema(type)
type <- arrow::as_data_type(type)
}

Expand All @@ -23,7 +23,7 @@ as_chunked_array.geoarrow_vctr <- function(x, ..., type = NULL) {
chunks <- nanoarrow::collect_array_stream(stream, validate = FALSE)
type <- arrow::as_data_type(type)

schema <- as_nanoarrow_schema(type)
schema <- nanoarrow::as_nanoarrow_schema(type)
arrays <- vector("list", length(chunks))
for (i in seq_along(arrays)) {
tmp_schema <- nanoarrow::nanoarrow_allocate_schema()
Expand All @@ -37,14 +37,14 @@ as_chunked_array.geoarrow_vctr <- function(x, ..., type = NULL) {
}

infer_type.geoarrow_vctr <- function(x, ...) {
arrow::as_data_type(as_nanoarrow_schema(x))
arrow::as_data_type(nanoarrow::as_nanoarrow_schema(x))
}

#' @export
as_geoarrow_array_stream.ChunkedArray <- function(x, ..., schema = NULL) {
stream <- nanoarrow::basic_array_stream(
lapply(x$chunks, as_nanoarrow_array),
schema = as_nanoarrow_schema(x$type),
lapply(x$chunks, nanoarrow::as_nanoarrow_array),
schema = nanoarrow::as_nanoarrow_schema(x$type),
validate = FALSE
)

Expand All @@ -54,8 +54,8 @@ as_geoarrow_array_stream.ChunkedArray <- function(x, ..., schema = NULL) {
#' @export
as_geoarrow_array_stream.Array <- function(x, ..., schema = NULL) {
stream <- nanoarrow::basic_array_stream(
list(as_nanoarrow_array(x)),
schema = as_nanoarrow_schema(x$type),
list(nanoarrow::as_nanoarrow_array(x)),
schema = nanoarrow::as_nanoarrow_schema(x$type),
validate = FALSE
)

Expand All @@ -69,7 +69,7 @@ GeometryExtensionType$create <- function(...) {

# this runs in .onLoad(), where we can't get coverage
# nocov start
register_arrow_extension_type_or_set_hook <- function(...) {
register_arrow_ext_or_set_hook <- function(...) {
# Register a hook for the arrow package being loaded to run the extension type
# registration
setHook(packageEvent("arrow", "onLoad"), register_arrow_extension_type)
Expand All @@ -90,7 +90,7 @@ register_arrow_extension_type <- function(...) {
public = list(

deserialize_instance = function() {
private$schema <- as_nanoarrow_schema(self)
private$schema <- nanoarrow::as_nanoarrow_schema(self)
private$parsed <- geoarrow_schema_parse(private$schema)
},

Expand Down Expand Up @@ -151,7 +151,7 @@ register_arrow_extension_type <- function(...) {
# when the Type object gets surfaced to R provided that the extension types
# have been registered.
GeometryExtensionType$create <- function(schema) {
schema <- as_nanoarrow_schema(schema)
schema <- nanoarrow::as_nanoarrow_schema(schema)
parsed <- geoarrow_schema_parse(schema)

arrow::new_extension_type(
Expand Down
5 changes: 3 additions & 2 deletions R/pkg-nanoarrow.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ register_geoarrow_extension <- function() {

#' @importFrom nanoarrow infer_nanoarrow_ptype_extension
#' @export
infer_nanoarrow_ptype_extension.geoarrow_extension_spec <- function(extension_spec, x, ...) {
infer_nanoarrow_ptype_extension.geoarrow_extension_spec <- function(extension_spec,
x, ...) {
nanoarrow::nanoarrow_vctr(schema = x, subclass = "geoarrow_vctr")
}

Expand Down Expand Up @@ -47,5 +48,5 @@ as_nanoarrow_array_extension.geoarrow_extension_spec <- function(
#' @importFrom nanoarrow convert_array
#' @export
convert_array.geoarrow_vctr <- function(array, to, ...) {
as_geoarrow_vctr(array, schema = as_nanoarrow_schema(to))
as_geoarrow_vctr(array, schema = nanoarrow::as_nanoarrow_schema(to))
}
4 changes: 2 additions & 2 deletions R/pkg-sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ st_as_sf.arrow_dplyr_query <- function(x, ..., promote_multi = FALSE) {

as_arrow_array.sfc <- function(x, ..., type = NULL) {
if (!is.null(type)) {
type <- as_nanoarrow_schema(type)
type <- nanoarrow::as_nanoarrow_schema(type)
}

arrow::as_arrow_array(as_geoarrow_vctr(x, schema = type))
}

as_chunked_array.sfc <- function(x, ..., type = NULL) {
if (!is.null(type)) {
type <- as_nanoarrow_schema(type)
type <- nanoarrow::as_nanoarrow_schema(type)
}

arrow::as_chunked_array(as_geoarrow_vctr(x, schema = type))
Expand Down
18 changes: 9 additions & 9 deletions R/pkg-wk.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ as_geoarrow_array.wk_wkt <- function(x, ..., schema = NULL) {
return(NextMethod())
}
} else {
schema <- infer_nanoarrow_schema(x)
schema <- nanoarrow::infer_nanoarrow_schema(x)
}

schema_storage <- nanoarrow::nanoarrow_schema_modify(
Expand All @@ -52,7 +52,7 @@ as_geoarrow_array.wk_wkb <- function(x, ..., schema = NULL) {
return(NextMethod())
}
} else {
schema <- infer_nanoarrow_schema(x)
schema <- nanoarrow::infer_nanoarrow_schema(x)
}

schema_storage <- nanoarrow::nanoarrow_schema_modify(
Expand All @@ -75,7 +75,7 @@ as_geoarrow_array.wk_xy <- function(x, ..., schema = NULL) {
}
}

schema <- infer_nanoarrow_schema(x)
schema <- nanoarrow::infer_nanoarrow_schema(x)
data <- unclass(x)
geoarrow_array_from_buffers(
schema,
Expand Down Expand Up @@ -114,12 +114,12 @@ infer_nanoarrow_schema.wk_xy <- function(x, ...) {

#' @export
convert_array.wk_wkt <- function(array, to, ...) {
schema <- infer_nanoarrow_schema(array)
schema <- nanoarrow::infer_nanoarrow_schema(array)
geo <- geoarrow_schema_parse(schema)
vctr <- as_geoarrow_vctr(array)

if (geo$extension_name == "geoarrow.wkt") {
out <- wk::new_wk_wkt(convert_array(force_array_storage(array)))
out <- wk::new_wk_wkt(nanoarrow::convert_array(force_array_storage(array)))
} else {
out <- wk::wk_handle(vctr, wk::wkt_writer())
}
Expand All @@ -132,12 +132,12 @@ convert_array.wk_wkt <- function(array, to, ...) {

#' @export
convert_array.wk_wkb <- function(array, to, ...) {
schema <- infer_nanoarrow_schema(array)
schema <- nanoarrow::infer_nanoarrow_schema(array)
geo <- geoarrow_schema_parse(schema)
vctr <- as_geoarrow_vctr(array)

if (geo$extension_name == "geoarrow.wkb") {
storage <- convert_array(force_array_storage(array))
storage <- nanoarrow::convert_array(force_array_storage(array))
# Comes back as a blob::blob
attributes(storage) <- NULL
out <- wk::new_wk_wkb(storage)
Expand All @@ -152,12 +152,12 @@ convert_array.wk_wkb <- function(array, to, ...) {

#' @export
convert_array.wk_xy <- function(array, to, ...) {
schema <- infer_nanoarrow_schema(array)
schema <- nanoarrow::infer_nanoarrow_schema(array)
geo <- geoarrow_schema_parse(schema)
vctr <- as_geoarrow_vctr(array)

if (geo$extension_name == "geoarrow.point") {
out <- wk::as_xy(convert_array(force_array_storage(array)))
out <- wk::as_xy(nanoarrow::convert_array(force_array_storage(array)))
} else {
out <- wk::wk_handle(vctr, wk::xy_writer())
}
Expand Down
Loading

0 comments on commit a6d44ef

Please sign in to comment.