Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add_row fails on sf object with bogus error message #662

Closed
alankjackson opened this issue Oct 4, 2019 · 5 comments
Closed

add_row fails on sf object with bogus error message #662

alankjackson opened this issue Oct 4, 2019 · 5 comments
Labels
vctrs ↗️
Milestone

Comments

@alankjackson
Copy link

alankjackson commented Oct 4, 2019


Applying add_row to an sf object emits the error:

Error: is.data.frame(.data) is not TRUE

yet that test is actually passed by the sf object. At minimum the error message
should be clearer.

library(tidyverse)
library(sf)

##   Create a tibble, and then make it an sf object

dftest <- tribble(
  ~tag, ~lat, ~lon,
  "a", 30.00000, -95.000000,
  "b", 30.10000, -95.100000
)

is.data.frame(dftest)

dftest <- st_as_sf(dftest, coords=c('lon', 'lat'), crs=4326)

is.data.frame(dftest)

add_row(dftest, tag="c")
@krlmlr
Copy link
Member

krlmlr commented Oct 23, 2019

With the most recent package versions, I'm now seeing:

library(tidyverse)
library(sf)
#> Linking to GEOS 3.6.2, GDAL 2.2.3, PROJ 4.9.3

dftest <- tribble(
  ~tag, ~lat, ~lon,
  "a", 30.00000, -95.000000,
  "b", 30.10000, -95.100000
)

dftest <- st_as_sf(dftest, coords=c('lon', 'lat'), crs=4326)

new_dftest <- add_row(dftest, tag = "a")
print(new_dftest)
#> Error in error_need_scalar(): could not find function "error_need_scalar"
attributes(new_dftest)
#> $names
#> [1] "tag"      "geometry"
#> 
#> $class
#> [1] "sf"         "tbl_df"     "tbl"        "data.frame"
#> 
#> $row.names
#> [1] 1 2 3

Created on 2019-10-23 by the reprex package (v0.3.0)

The operation succeeds but creates an invalid sf object.

@edzer: Would you like add_row() to work with sf objects?

@edzer
Copy link

edzer commented Oct 23, 2019

I haven't run into needing it, but I wouldn't object if it worked!

@krlmlr
Copy link
Member

krlmlr commented Oct 23, 2019

For this to work, sf needs to be at least aware of vctrs -- or the other way round...

@krlmlr krlmlr added the vctrs ↗️ label Oct 23, 2019
@krlmlr krlmlr closed this as completed in 79cd808 Oct 23, 2019
@krlmlr
Copy link
Member

krlmlr commented Oct 23, 2019

Calling vec_restore() fixes the issue but still downgrades the sf object into a plain tibble.

@krlmlr krlmlr added this to the 3.0.0 milestone Mar 21, 2020
@github-actions
Copy link

github-actions bot commented Mar 22, 2021

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
vctrs ↗️
Projects
None yet
Development

No branches or pull requests

3 participants