2

In an effort to make reproducible posts at SO, I am trying to download data files to a temporary location and from there to load them into R. I am mostly using code from JD Longs answer in this SO Post. The downloading and unzipping works all fine, but I am unable to load the file from the temporary directory. This is the code I am using:

library(maptools)
tmpdir <- tempdir()
url <- 'http://epp.eurostat.ec.europa.eu/cache/GISCO/geodatafiles/NUTS_2010_03M_SH.zip'
file <- basename(url)
download.file(url, file)
unzip(file, exdir = tmpdir )

## I guess the error is somewhere in the next two lines
shapeFile <- paste(tmpdir,"/Shape/data/NUTS_RG_03M_2010")
EU <- readShapeSpatial(shapeFile)
# --> Error in getinfo.shape(fn) : Error opening SHP file

I have been looking into the man files for tempdir() without success. Settinge the working directory to the temporary location didn't work either. I probably miss something very basic here. Do you have any hints how to get around this?

Community
  • 1
  • 1
Tungurahua
  • 489
  • 7
  • 21
  • 1
    `shapeFile <- paste(tmpdir,"/Shape/data/NUTS_RG_03M_2010", sep="")`. As default, `paste` use a space as separator, which cause the path to be wrong. – plannapus Oct 12 '12 at 08:49
  • 1
    @Tungurahua, perhaps you should post your comment as an answer, to get this out of the unsanswered queue. – MvG Oct 12 '12 at 11:49
  • Argl, above comment should have gone to @plannapus. Sorry there. – MvG Oct 12 '12 at 12:00

1 Answers1

3
shapeFile <- paste(tmpdir,"/Shape/data/NUTS_RG_03M_2010", sep="")

As default, paste use a space as separator, which cause your path to be wrong. Of course, the alternative, as of R 2.15.0, would be paste0:

shapefile <- paste0(tmpdir,"/Shape/data/NUTS_RG_03M_2010")
plannapus
  • 18,529
  • 4
  • 72
  • 94