[R-sig-Geo] Material for asdar book
Roger Bivand
Roger.Bivand at nhh.no
Sat Jan 3 16:18:43 CET 2009
On Fri, 2 Jan 2009, Barry Rowlingson wrote:
> 2009/1/2 Roger Bivand <Roger.Bivand at nhh.no>:
>
>> $ more run_tests.sh
>> #! /bin/bash
>> export ASDAR="http://www.asdar-book.org/"
>> export ASDAR_BUNDLES="${ASDAR}bundles"
>>
>> CHAPTERS="hello cm vis die cm2 csdacm sppa geos lat1 lat2 dismap"
>>
>> for ch in $CHAPTERS; do
>> if test -d ${ch}
>> then cd ${ch}
>> else
>> mkdir ${ch}
>> cd ${ch}
>> fi
>> wget -N "${ASDAR_BUNDLES}/${ch}_bundle.zip"
>> unzip -o "${ch}_bundle.zip"
>> cd ..
>> done
>>
>> This generates a directory for each chapter, but you could do it otherwise
>> if you prefer. As you will have seen, the R scripts in each chapter unpack
>> the data set zip archives. We can look at trying to get PHP to do this
>> dynamically, but I guess a scripting solution is good enough?
>
> Why not an R solution using download.file?
Here you are:
ASDAR_BUNDLES <- "http://www.asdar-book.org/bundles"
ci <- structure(list(hello = c("data1964al.xy", "hello_mod.R"),
cm = c("auck_gshhs.RData", "CRAN051001a.txt", "legend_image.R",
"70042108.zip", "auckland_mapgen.dat", "seamap105_mod.csv", "cm_mod.R",
"high.RData", "state.sat.data_mod.txt"),
vis = "vis_mod.R",
die = c("70042108.zip", "die_mod.R", "legend_image.R", "snow_files.zip"),
cm2 = c("70042108.zip", "90mfips.txt", "auck_gshhs.RData", "cm2_mod.R"),
csdacm = c("csdacm_mod.R", "seamap105_mod.csv", "70042108.zip"),
sppa = c("sppa_mod.R", "cv.R", "north_derby_asthma.zip"),
geos = c("geos_mod.R", "m1m2.R"),
lat1 = c("lat1_mod.R", "NY_data.zip", "Sy_GeoDa1.GAL", "Sy_GeoDa2.GAL",
"Sy_GeoDa4.GWT"),
lat2 = c("lat2_mod.R", "NY_data.zip"),
dismap = "dismap_mod.R"), .Names = c("hello", "cm", "vis", "die", "cm2",
"csdacm", "sppa", "geos", "lat1", "lat2", "dismap"))
for (i in names(ci)) {
fn <- paste(i, "_bundle.zip", sep = "")
download.file(paste(ASDAR_BUNDLES, "/", fn, sep = ""), fn)
if (!file.exists(i)) dir.create(i)
for (j in ci[[i]]) {
zfn <- zip.file.extract(j, fn)
file.copy(zfn, paste(i, j, sep=.Platform$file.sep))
}
}
I think that Python would have been easier, because it has - and I can't
see that R has - a way of looking up the table of contents of a zipfile,
so here I've fudged the issue by canning the contents. Any other portable
languages?
Roger
>
> Barry
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list