4

I'm trying to import a shape-file like this:

fn <- "Proj1"
my_shp <- readShapeSpatial(fn)

On a windows-computer (32-bit) it works ok, but when I do the same from a Ubuntu-machine (64-bit, English OS, R2.14.0), I get "Error in make.names(onames, unique = TRUE) : invalid multibyte string 9".

I suspect it is because the shapefile has Spanish origins, i.e. the names of polygons in it have accents like in "México" (not "Mexico").

As a quick fix, I did the import in windows, saved as .rda and loaded it in Ubuntu, but then I get for example "M\xfexico" as polygon name.

I'm not so experienced in Linux so I don't know if the fix is in R or in Ubuntu. Your help is highly appreciated.

Paul Hiemstra
  • 59,984
  • 12
  • 142
  • 149
Chris
  • 2,256
  • 1
  • 19
  • 41
  • 1
    I think the problem is related to the encoding of your file. Maybe this [discussion at the R-br help list](http://r-br.2285057.n4.nabble.com/R-br-Erro-ao-importar-mapa-Shapefile-tp4023591p4024488.html) is useful for you. – Oscar Perpiñán Jan 30 '12 at 12:06
  • Thanks! I read the email-chain and launched R from a terminal with "LC_ALL=C R", and that did it. Obrigado! – Chris Jan 30 '12 at 12:55
  • You should post an answer and checkmark it so it doesn't linger forever in the unanswered queue, Chris. – IRTFM Jan 30 '12 at 15:50

1 Answers1

3

The solution is to start R on the Ubuntu-computer by writing "LC_ALL=C R" in a terminal window. Thanks to Oscar Perpiñán for the solution.

Update: I use RStudio, where as far as I know it is not possible to start R with command-line parameters, but this works from inside RStudio: Sys.setlocale(category = "LC_ALL", locale = "C")

/Chris

Chris
  • 2,256
  • 1
  • 19
  • 41