dime-worldbank / googletraffic

R package to query Google Maps traffic data and transform into data
Other
58 stars 9 forks source link

Got errors in hex_to_rgb. #17

Closed quqixun closed 4 months ago

quqixun commented 4 months ago

Rencently, I got these errors:

Error in hex_to_rgb(hex = hex) : 
  The following colours do not have six digits:
 1
Calls: gt_make_raster -> gt_html_to_raster -> gt_load_png_as_traffic_raster

How to fix it? Thanks.

TessarolloTRT commented 4 months ago

I found the same issue. I've tried to have a look at the process and I found out that at line 82 of gt_load_png_as_traffic_raster.R the procedure creates a list of colours found in the image. a new column is added at the list named "hex_noff" which is filled with hex colours whith an exeption: white loose two F (#FFFF instead of #FFFFFF). Line 82 adds this column ("hex_noff") replacing "FF" with "". I haven't got a solution, I hope that this analysis may help finding one :)

quqixun commented 4 months ago

I found the same issue. I've tried to have a look at the process and I found out that at line 82 of gt_load_png_as_traffic_raster.R the procedure creates a list of colours found in the image. a new column is added at the list named "hex_noff" which is filled with hex colours whith an exeption: white loose two F (#FFFF instead of #FFFFFF). Line 82 adds this column ("hex_noff") replacing "FF" with "". I haven't got a solution, I hope that this analysis may help finding one :)

Thanks for pointing this out. I forked the repo and modified code to save html and png to custom location instead of tempdir. It is not a solution, but data can be preserved before finding one.

TessarolloTRT commented 4 months ago

I've modified the procedure: I've deleted the modification of the hex colour (keeping all F for white) and everything seesms to work now :)

quqixun commented 4 months ago

I've modified the procedure: I've deleted the modification of the hex colour (keeping all F for white) and everything seesms to work now :)

It's a good idea. I modified gt_load_png_as_traffic_raster.R to keep all F for white as you suggested:

## Color Values
color_df <- rimg[] %>% 
  unique() %>% 
  as.data.frame() %>%
  dplyr::rename(hex = ".") %>%
  dplyr::mutate(hex_noff = str_replace_all(.data$hex, "FF$", "FF"))

Then it works. Thanks a lot.

ramarty commented 4 months ago

Thanks @quqixun and @TessarolloTRT -- I modified the code and will get the changes on CRAN soon!