0

I have coded

canada_raw <- readOGR(dsn = "data/gcd_000b11a_e", 
                      layer = "gcd_000b11a_e", 
                      use_iconv=TRUE, 
                      encoding="CP1250")


canada_raw_json <- geojson_json(canada_raw)
canada_raw_sim <- ms_simplify(canada_raw_json)

I am getting an error message I dont know how to handle it

error message is

Error: lexical error: invalid bytes in UTF8 string.
          CDUID": "2485", "CDNAME": "Témiscamingue", "CDTYPE": "MRC", 
                     (right here) ------^
Daniel V
  • 1,305
  • 7
  • 23
julia
  • 21
  • 5
  • We can't reproduce this, because we don't have your data file, you haven't included full code, and you didn't say when the error occurred. Was it on the first command, second or third? – user2554330 Nov 26 '19 at 01:12

1 Answers1

0

I think your actual problem has to do with character encoding, which has been raised/addressed here. I can't replicate your error message.

# set encoding
options(encoding = "UTF-8")

# packages
if (("geojsonio" %in% rownames(installed.packages()))==FALSE) install.packages("geojsonio"); library(geojsonio)
if (("geojsonlint" %in% rownames(installed.packages()))==FALSE) install.packages("geojsonlint"); library(geojsonlint)
if (("devtools" %in% rownames(installed.packages()))==FALSE) install.packages("devtools"); library(devtools)
if (("rgdal" %in% rownames(installed.packages()))==FALSE) install.packages("rgdal"); library(rgdal)
install_github("ateucher/rmapshaper")

# grab the file from "Statistics Canada"
url<-"http://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gcd_000b11a_e.zip"
n<-basename(url)
download.file(url,
              destfile = n)
unzip(n,exdir = substr(n,1,nchar(n)-4))

canada_raw<-readOGR(file.choose(),use_iconv = TRUE,encoding = "CP1250")
canada_raw_json <- geojsonio::geojson_json(canada_raw)
canada_raw_sim <- rmapshaper::ms_simplify(canada_raw_json)

still having the same error

Error: lexical error: invalid bytes in UTF8 string. CDUID": "2485", "CDNAME": "Témiscamingue", "CDTYPE": "MRC", (right here) ------^