chgrl / leafletR

An R package to create interactive web-maps based on the Leaflet JavaScript library
GNU General Public License v3.0
63 stars 19 forks source link

lexical error: invalid bytes in UTF8 string #25

Closed gingerYD closed 9 years ago

gingerYD commented 9 years ago

Recently I ran an old program that I created six months ago, and encountered an UTF-8 encoding error. It was fine a couple of months ago.

Error in feed_push_parser(buf) : lexical error: invalid bytes in UTF8 string. properties": { "County": "Doña Ana County, New Mexico", "Pop (right here) ------^

banyh commented 9 years ago

I had the same problem, and found one way to fix it.

Cause: In spToGeoJSON.R, properties are outputed to JSON file by cat. For example: cat(",", file=path, append=TRUE, sep="\n"). The output file is opened with your system default encoding. When you run getOption("encoding"), you'll get [1] "native.enc". And your native.enc is not utf8. That why property strings are converted to wrong encoding.

Solution: options(encoding = "utf8") before you run toGeoJSON.

My suggestion: file=path can be replaced by file=connect, where connect <- file(path, "w", encoding="utf8").

gingerYD commented 9 years ago

Thank you. This solution works!

JeffersonEmanuel commented 7 years ago

Thank you!!

felipe-mejia commented 7 years ago

Thank you!