r-tmap / tmap

R package for thematic maps
https://r-tmap.github.io/tmap
GNU General Public License v3.0
865 stars 121 forks source link

tm_markers error in v3 and v4 #913

Open see24 opened 2 months ago

see24 commented 2 months ago

I have been getting an error when using tm_markers with either tmap 3.99 or 3.99.9001

This simple example causes different errors in each version.

library(tmap)
#> Breaking News: tmap 3.x is retiring. Please test v4, e.g. with
#> remotes::install_github('r-tmap/tmap')

data("metro")

tm_shape(metro) +
   tm_markers()

With v3 I get:

#> old-style crs object detected; please recreate object with a recent sf::st_crs()
#> old-style crs object detected; please recreate object with a recent sf::st_crs()
#> old-style crs object detected; please recreate object with a recent sf::st_crs()
#> old-style crs object detected; please recreate object with a recent sf::st_crs()
#> old-style crs object detected; please recreate object with a recent sf::st_crs()
#> Error in if (borderlwd == 0) { : missing value where TRUE/FALSE needed

While with v4 I get:

#> Error: C:/R/library/leaflet/htmlwidgets/lib/leaflet/images/marker-icon.png is neither a valid path nor url

I did a little digging and I wonder if the problem might be here?:

https://github.com/r-tmap/tmap/blob/f916c7ed2756989ccd3a927b48c75f6147816990/R/tm_layers_text.R#L694

It looks like a_dots is used when I think it ought to be args_dots. Not sure if that is the problem here but seems like it might be a typo.

mtennekes commented 2 months ago

Indeed a typo, thx! However this is unrelated to this issue.

Could you test file.exists(system.file("htmlwidgets/lib/leaflet/images/marker-icon.png", package="leaflet"))? It should return TRUE.

Not sure about the v3 error, but this has low priority.

see24 commented 2 months ago

Yes that returns TRUE but the path returned by system.file is different from the one shown in the error message

mtennekes commented 2 months ago

Strange. What is your output of tmap_icon()? Is the URL in the list item iconUrl the same as in the error message?

see24 commented 2 months ago

tmap::tmap_icon() gives an error because the file argument is missing. I think maybe you meant tmap::marker_icon()?

tmap::marker_icon()
#> $iconUrl
#> [1] "C:/Users/EndicottS/AppData/Local/Programs/R/R-4.4.1/library/leaflet/htmlwidgets/lib/leaflet/images/marker-icon.png"
#> 
#> $iconWidth
#> [1] 25
#> 
#> $iconHeight
#> [1] 41
#> 
#> $iconAnchorX
#> [1] 12
#> 
#> $iconAnchorY
#> [1] 41
#> 
#> attr(,"class")
#> [1] "tmap_icons"

Created on 2024-08-20 with reprex v2.1.1

I am guessing there is some problem because R is installed locally for me as a user rather that under C. But system.file should handle that so I wonder if there is somewhere that is not using system.file when it should?

mtennekes commented 2 months ago

The iconUrl points to a local installation indeed, which is also hosted on your C drive, but not in the general Program Files.

What does file.exists("C:/Users/EndicottS/AppData/Local/Programs/R/R-4.4.1/library/leaflet/htmlwidgets/lib/leaflet/images/marker-icon.png") return?

If TRUE you could probably work around this problem by

tm_shape(metro) +
   tm_markers(shape = tmap::marker_icon())
goneau commented 1 month ago

Hi, I am following a class in R and I encounter the same issue using tm_markers()

Erreur dans if (borderlwd == 0) { : valeur manquante là où TRUE / FALSE est requis

I tested file.exists("C:/Users/Goneau/AppData/Local/Programs/R/R-4.4.1/library/leaflet/htmlwidgets/lib/leaflet/images/marker-icon.png") and it returned TRUE, so I tried tm_markers(shape = tmap::marker_icon()), but I have the same error.

olivroy commented 1 month ago

@goneau Please update to the v4 development version with https://github.com/r-tmap/tmap?tab=readme-ov-file#development. The bug in v3 is unlikely to be fixed.

I get the following map with the map you shared in view mode. image

goneau commented 1 month ago

Using the development version solve the issue. Unfortunately, I now have errors with tm_raster() not compiling the code from the textbook.

olivroy commented 1 month ago

Hi @goneau, thanks for testing. Feel free to open a new issue about that with a reproducible example! tmap v4 is almost ready and it is exactly those kinds of cases we want to cover before releasing to CRAN