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

tm_markers error in v3 and v4 #913

Open
see24 opened this issue Aug 13, 2024 · 9 comments
Open

tm_markers error in v3 and v4 #913

see24 opened this issue Aug 13, 2024 · 9 comments
Labels

Comments

@see24
Copy link
Contributor

see24 commented Aug 13, 2024

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?:

tm_d = do.call(tm_dots, a_dots)

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 added a commit that referenced this issue Aug 13, 2024
@mtennekes
Copy link
Member

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
Copy link
Contributor Author

see24 commented Aug 13, 2024

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

@mtennekes
Copy link
Member

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

@see24
Copy link
Contributor Author

see24 commented Aug 20, 2024

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
Copy link
Member

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
Copy link

goneau commented Sep 12, 2024

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
Copy link
Contributor

olivroy commented Sep 12, 2024

@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
Copy link

goneau commented Sep 13, 2024

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

@olivroy
Copy link
Contributor

olivroy commented Sep 13, 2024

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

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

No branches or pull requests

5 participants