markerColourIconCheck() fixes error being thrown when allowed colou…#235
markerColourIconCheck() fixes error being thrown when allowed colou…#235merlinoa wants to merge 2 commits into
markerColourIconCheck() fixes error being thrown when allowed colou…#235Conversation
|
Thanks for the PR - I think it looks good; will give it a full test later today (Australian time) |
|
|
||
| if(!is.null(colour)){ | ||
| if(!all((tolower(data[, colour])) %in% c("red","blue","green","lavender"))){ | ||
| if(!all((tolower(data[["colour"]])) %in% c("red","blue","green","lavender"))){ |
There was a problem hiding this comment.
I think this should actually be data[[colour]] - without the quotes. Because otherwise it's looking for a column called "colour".
There was a problem hiding this comment.
Yea that is what it is doing. The column in the data data frame is called "colour".
There was a problem hiding this comment.
Can you give an example which generates the error you're seeing?
For me this works
library(googleway)
set_key(secret::get_secret("GOOGLE"))
df <- tram_stops
df$colour <- sample(c("red","blue","lavender"), size = nrow(df), replace = T)
google_map() %>%
add_markers(
data = df
, colour = "colour"
)
There was a problem hiding this comment.
The docs for the colour argument state: "string specifying the column containing the 'colour' to use for the markers. One of 'red', 'blue', 'green' or 'lavender'"
If you pass "red", "blue", "green" or "levendar" to the colour argument you get an error.
There was a problem hiding this comment.
The string you pass to the colour argument must specify the column of the data.
There was a problem hiding this comment.
Ok -- If that is how the argument should work, IMO it would be more clear to document it something like "the string 'colour' if you are setting the colour of the marker or NULL to use the default marker colour". I made this PR because a client of mine was confused by the docs.
In general though, don't you want to actually pass the colour to the colour argument, not the string "colour"? By passing the string "colour" you can't actually set the colour.
There was a problem hiding this comment.
The string 'colour' is just what I named the column of the data. You can name the column of data anything you like.
The colour argument works in the same way as the lon, lat, and many of the others; you use them to tell the the function which column of data holds that variable.
Here's another example where the column my_column holds the marker colours.
library(googleway)
set_key(secret::get_secret("GOOGLE"))
df <- tram_stops
df$my_column <- sample(c("red","blue","lavender"), size = nrow(df), replace = T)
google_map() %>%
add_markers(
data = df
, lon = "stop_lon" ## column name
, lat = "stop_lat" ## column name
, colour = "my_column" ## column name
)
…rs used
Thanks for the excellent package! When using one the allowed colours in
add_marker(), I was running into this error:I traced down the error to the check in the
markerColourIconCheck()function. The below PR resolves the above error. The @param documentation has also been updated to reflect how it looked like the argument was actually being used.Just a suggestion -- I would change the argument name to "check_colour" and make it a boolean because the actual string value of the "colour" or NULL is not used in the check; the colours in the "colour" column of data are what is actually checked. I did not make this change because I wanted to change as little as possible. Thanks again for great package!