R-ArcGIS / arcgislayers

Access ArcGIS Data and Location Services
http://r.esri.com/arcgislayers/
Apache License 2.0
44 stars 10 forks source link

Integers parsed as date times #211

Open grcatlin opened 3 months ago

grcatlin commented 3 months ago

Describe the bug From commit 553e80b508f1d0a72448e86e06858b3eb381c9f7 onward, integer fields seem to be parsed as date times for some reason. The previous commit (c988b92760833d7593e8be7a2b3dda2a98b348ec) parses normally. However, from 553e80b508f1d0a72448e86e06858b3eb381c9f7 onward, when I hit a integer field it reads as 1969-12-31 17:00:INTEGER.

I.E., I have a temperature field where an observer put in 34, this now reads as 1969-12-31 17:00:34. This is the same whether using argislayers::arc_open() + arcgislayers::arc_select() or just arcgislayers::arc_read().

To Reproduce Unfortunately, the feature service in question is sensitive and cannot be shared but here is my general workflow:

token <- function() {
    arcgisutils::auth_user(
        username = Sys.getenv("ESRI_USER"),
        password = Sys.getenv("ESRI_PWD")
    )
}

service <- arcgislayers::arc_open(
    "url",
    token = token()
)

arcgislayers::arc_select(service, token = token()) |>
    dplyr::select(males, females, unknown, temp) |>
    sf::st_drop_geometry() |>
    head() |>
    kableExtra::kable()
males females unknown temp
1969-12-31 17:00:18 1969-12-31 17:00:01 1969-12-31 17:00:00 1969-12-31 17:00:50
1969-12-31 17:00:45 1969-12-31 17:00:02 1969-12-31 17:00:00 1969-12-31 17:00:45
1969-12-31 17:00:60 1969-12-31 17:00:04 1969-12-31 17:00:00 1969-12-31 17:00:45
1969-12-31 17:00:18 1969-12-31 17:00:03 1969-12-31 17:00:00 1969-12-31 17:00:45
1969-12-31 17:00:22 1969-12-31 17:00:12 1969-12-31 17:00:00 1969-12-31 17:00:60
1969-12-31 17:00:01 1969-12-31 17:00:01 1969-12-31 17:00:01 1969-12-31 17:00:40

Additional context Not sure if it would matter but my feature service is from a Survey123 application where the offending fields are specified as:

type name label required
integer males Males: true
integer females Females: true
integer unknown Number Unknown: true
integer temp Temperature (F): true

and so forth in the xlsform.

Additionally, I don't believe I have any integers >= 100 which may change how it would be parsed?

JosiahParry commented 3 months ago

Can you please try installing arcpbf from r-universe?

install.packages("arcpbf", repos = c("https://r-arcgis.r-universe.dev", "https://cloud.r-project.org"))

then restart R and try loading your feature service? I believe I fixed this bug previously this week.

grcatlin commented 3 months ago

Hi there, thanks for the quick response!

Install via Remotes

On installing dev version from remotes::

remotes::install_github("r-arcgis/arcgislayers", force = TRUE)
remotes::install_github("r-arcgis/arcpbf", force = TRUE)

# restart R

devtools::package_info(c("arcgislayers", "arcpbf")) |>
    dplyr::filter(stringr::str_starts(package, "arc")) |>
    dplyr::select(package, "ondiskversion", date, source) |>
    data.table::as.data.table() |>
    kableExtra::kable()
package ondiskversion date source
arcgislayers 0.3.0.9000 2024-07-20 Github (r-arcgis/arcgislayers@754bd2d95c76bf3b286c6f765ab2d5318eb0eca5)
arcgisutils 0.3.0 2024-05-09 CRAN (R 4.4.1)
arcpbf 0.1.3.9000 2024-07-20 Github (r-arcgis/arcpbf@5d1a74b2bce2faeb8002a57a600d8371ee488fbf)

When trying to arcgislayers::arc_read():

Error in `arc_select()`:
! `as.integer(page_size)` must be a whole number or `NULL`, not an empty integer vector.

Backtrace:
    ▆
 1. └─arcgislayers::arc_read(...)
 2.   └─arcgislayers::arc_select(...)
 3.     └─arcgislayers:::check_number_whole(...)
 4.       └─arcgislayers:::.stop_not_number(...)
 5.         └─arcgislayers:::stop_input_type(...)
 6.           └─rlang::abort(message, ..., call = call, arg = arg)

Install via https://r-arcgis.r-universe.dev

On installing via install.packages():

install.packages("arcpbf", repos = c("https://r-arcgis.r-universe.dev", "https://cloud.r-project.org"))
install.packages("arcgislayers", repos = c("https://r-arcgis.r-universe.dev", "https://cloud.r-project.org"))

# restart R
package ondiskversion date source
arcgislayers 0.3.0.9000 2024-07-20 https://r-arcgis.r-universe.dev (R 4.4.1)
arcgisutils 0.3.0 2024-05-09 CRAN (R 4.4.1)
arcpbf 0.1.3.9000 2024-07-20 https://r-arcgis.r-universe.dev (R 4.4.1)

I get the same

Error in `arc_select()`:
! `as.integer(page_size)` must be a whole number or `NULL`, not an empty integer vector.

Install via CRAN

On installing from CRAN:

install.packages("arcpbf", repos = c("https://cloud.r-project.org"))
install.packages("arcgislayers", repos = c("https://cloud.r-project.org"))

# restart R
package ondiskversion date source
arcgislayers 0.3.0 2024-07-05 CRAN (R 4.4.1)
arcgisutils 0.3.0 2024-05-09 CRAN (R 4.4.1)
arcpbf 0.1.3 2024-07-10 CRAN (R 4.4.1)

arcgislayers::arc_read() works but give the weird 1969-12-31 17:00:INTEGER thing.

Finally, Install dev arcpbf + CRAN arcgislayers

On installing dev version of arcpbf w/ CRAN of arcgislayers:

package ondiskversion date source
arcgislayers 0.3.0 2024-07-05 CRAN (R 4.4.1)
arcgisutils 0.3.0 2024-05-09 CRAN (R 4.4.1)
arcpbf 0.1.3.9000 2024-07-20 https://r-arcgis.r-universe.dev (R 4.4.1)

It parses as expected.

grcatlin commented 3 months ago

212 specifically regards the

Error in `arc_select()`:
! `as.integer(page_size)` must be a whole number or `NULL`, not an empty integer vector.