1

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
  • 469
  • 5
  • 21

1 Answers1

2
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,099
  • 4
  • 72
  • 92