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

editFeatures: Dollar operator invalid on shapefile #66

Open
brry opened this issue Dec 5, 2017 · 3 comments
Open

editFeatures: Dollar operator invalid on shapefile #66

brry opened this issue Dec 5, 2017 · 3 comments

Comments

@brry
Copy link

brry commented Dec 5, 2017

editFeatures with a personal shapefile read with sf does not work.
Using the latest CRAN versions denoted in reprex below.
Turns up on Win 10, 64 bit, R version 3.4.2 (2017-09-28).

library(mapview) # 2.2.0
library(mapedit) # 0.3.2

download.file("https://github.com/brry/course/raw/master/data/PrecBrandenburg.zip", 
              destfile="prec.zip")
unzip("prec.zip")
p <- sf::st_read("PrecBrandenburg/niederschlag.shp")

ed <- editFeatures(franconia) # works fine
ed <- editFeatures(p) # Error in x$edit_id : $ operator is invalid for atomic vectors

berryFunctions::tryStack( editFeatures(p) )
# sys.calls: berryFunctions::tryStack -> editFeatures -> editFeatures.sf -> 
# mapview::addFeatures -> addPolygonFeatures -> garnishMap -> do.call - fn_lst[[i]] 
# ->  -> invokeMethod -> eval -> eval -> invokeMethod -> evalFormula -> evalAll 
# -> lapply -> FUN -> resolveFormula -> eval -> eval -> x$edit_id

(Don't try traceback(). With the do.call stuff, it will print entire objects. tryStackfilters that out.)

@timelyportfolio
Copy link
Contributor

Thanks for the report @brry, this is strange behavior, so will be good to debug.

@timelyportfolio
Copy link
Contributor

timelyportfolio commented Dec 6, 2017

Well, not what I wanted to find, but it seems the x column confuses leaflet evalFormula. For instance, removing the x column means all works, or at least on my machine.

editFeatures(x[,-2]) # x is the 2nd column

I will work on a solution within mapedit or potentially raise issue over at leaflet.

@tim-salabim
Copy link
Member

At a very quick glance I can confirm that changing the column name also works.

names(p)[2] = "x1"
editFeatures(p)

If this is really caused by evalFormula I guess it is better to be addressed at the source, i.e. in leaflet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants