editFeatures: Dollar operator invalid on shapefile
brry opened this issue · comments
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. tryStack
filters that out.)
Thanks for the report @brry, this is strange behavior, so will be good to debug.
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
.
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.