geojson serializer incorrectly displays integer64
timeddilation opened this issue · 2 comments
timeddilation commented
Describe the bug
Given an integer64 property on an sf object
When plumber serializes the sf object as a geojson
Then the integer64 is returned as infinitesimally small value
To Reproduce
In my particular use case, I'm using geometry objects from tigris
, so here is a trimmed example of the problem.
Create a plumber.R
file. Paste the following code in it, run the API, and execute the endpoint:
library(plumber)
library(data.table)
library(bit64)
library(sf)
library(sp)
library(tigris)
library(geojsonsf)
options(tigris_use_cache = TRUE)
#* @apiTitle Geojson Bug Reprex
#* Get a geojson of all county subdivisions in Monroe County, PA
#* @get /pa_monroe_cousubs
#* @serializer geojson
function(){
cousubs <- county_subdivisions(state = "42", county = "089") |>
as.data.table()
cousubs_dt <-
cousubs[order(GEOID), .(
id = as.integer64(GEOID),
GEOID,
NAME
)]
row.names(cousubs_dt) <- gsub("^", "ID", row.names(cousubs_dt))
cousubs_sf <-
cousubs[order(GEOID), geometry] |>
as_Spatial() |>
SpatialPolygonsDataFrame(data = cousubs_dt) |>
st_as_sf()
return(cousubs_sf)
}
Expected behavior
Returns the id
as an integer. Expected result is:
"features": [
{
"type": "Feature",
"properties": {
"id": 4208904320,
"GEOID": "4208904320",
"NAME": "Barrett"
} ...
Instead we get:
"features": [
{
"type": "Feature",
"properties": {
"id": 2.079475031e-314,
"GEOID": "4208904320",
"NAME": "Barrett"
} ...
CLI:
Reproduced in both:
- OS: Ubuntu 20.04 AND Windows 10
- R versions 4.2.1 AND 4.1.2
- Plumber version 1.2.1
blinktag commented
@timeddilation I think you want to submit to this repo instead https://github.com/rstudio/plumber
timeddilation commented
bahaha, sorry about that...