s-news
[Top] [All Lists]

Re: function to download data from internet into Splus

To: nikolay <niskrev@umich.edu>
Subject: Re: function to download data from internet into Splus
From: Prof Brian Ripley <ripley@stats.ox.ac.uk>
Date: Tue, 27 May 2003 07:59:15 +0100 (BST)
Cc: s-news@lists.biostat.wustl.edu
In-reply-to: <001e01c323ee$11396ab0$690cd38d@Inspiration>
On Mon, 26 May 2003, nikolay wrote:

> given below is an example of a function written by Diethelm Wurtz with which
> one can download data from a web site (econmagic.com) into Splus. The
> function works under Unix. Does anyone know an easy way to make it work with
> Splus 6.0 under Windows

It is extremely unlikely to work under Unix, since it uses \ as a path
separator, and S-PLUS for Unix does not have a system() command. (I'd be
interested to see your evidence that it does.)  I am almost certain it was
intended to be used under Windows!

The grep line is not needed if wget -O file -o tempfile had been used.
Then all you would need is a wget for Windows.  For historical reasons
there is one in http://www.stats.ox.ac.uk/pub/Rtools/wget.zip

Hardcoding the paths to tools is not good practice: drop the bin\ and
put the tools in your PATH.

> "import.data.economagic" <- function(file, source, query) {
> # Download Data:
> tmpfile <- tempfile(file); on.exit(unlink(tmpfile))
> print("Starting Internet Download ...")
> system(paste("bin\\wget -O ", file, " ", source, query, sep=""),
> on.exit.status="stop", minimized=T)
> print("Data successfully downloaded ...")
> system(paste("bin\\cat ", file, " | bin\\grep '^ [12][90].. [01].' > ",
> tmpfile, sep=""), on.exit.status="stop", minimized=T)
> # Transform Data:
> z <- read.table(tmpfile)
> z <- data.frame(cbind(z[,1]*100+z[,2], z[,3:(length(names(z)))]))
> # Save as Data Frame:
> znames <- as.character(1:(length(names(z))-1))
> names(z) <- c("DATE", znames)
> write.table(z, file=file, dimnames.write="colnames")
> # Return Result:
> z }


-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


<Prev in Thread] Current Thread [Next in Thread>