Download a File from the Internet

DESCRIPTION:

Download a file from the Internet and save the result in a file.

USAGE:

download.file(url, destfile, method="internal", quiet=TRUE, mode="w",
              ..., verbose=!quiet, download.args=list(...))

REQUIRED ARGUMENTS:

url
a character string containing the URL of the resource to be downloaded. The URL should include the transport protocol e.g. "http://" or "ftp://".
destfile
a character string specifying the name of where the downloaded file is saved.

OPTIONAL ARGUMENTS:

method
a character string specifying the method for the download. Currently only the default "internal" is supported.
quiet
a logical value, if TRUE, status messages are not printed.
mode
a character string denoting the mode for writing the file. Possible values are: xxxx.
...
additional arguments can set using name=value. These will get combined in the download.args list. See the details section for the types of additional arguments that can be supplied. The additional arguments should either be supplied in the name=value form or in the download.args list but not both.
verbose
a logical value, if TRUE, status messages are printed.
download.args
a named list of additional arguments. The default value for this is all the additional arguments supplied in name=value form. If a value for download.args is supplied then the additional arguments supplied in name=value form will be ignored. See the details section for the types of additional arguments that can be supplied.

VALUE:

the number of bytes downloaded.

SIDE EFFECTS:

The file destfile is created.

DETAILS:

The function download.file uses the CURL library, see the reference.

Possible values to supply in the ... or on the download.args list:

postfields = "string" - The full data to post in an HTTP POST operation. You must make sure that the data is formatted the way you want the server to receive it. The data will not be converted or encoded by the function. Most web servers will assume this data to be url-encoded.

userpwd = "username:password" - A user name and password to use for the connection.

proxy = "hostname" or proxy = "http://hostname" or proxy = "http://hostname:port" - Set HTTP proxy to use.

proxyuserpwd = "username:password" - the user name and password to use for the connection to the HTTP proxy.

Environment Variables for Proxy Server:

If http connections must go through a proxy server you can use the environment variable "http_proxy" to set the URL of the proxy and the username:password combination possibly required by the proxy. The format is "http://hostname" (or "http://hostname:port") if no username or password is required and "http://username:password@hostname" (or "http://username:password@hostname:port"), where "hostname" is the name of the proxy and "port" is its port number (default 80) on that host.

You can set the environment variable http_proxy before starting Splus. It will affect other programs using the CURL library and some other intenet connectivity libraries. This is the recommended way to pass proxy information to download.file when using functions that call it, such as download.packages. (On Unix-like platforms you can use Sys.setenv to set it before your first call to download.file.)

REFERENCES:

The cURL web site: http://curl.haxx.se/.

SEE ALSO:

EXAMPLES:

# Get a copy of Google's home page, store in a tempfile
gtmpfile <- tempfile("google")
download.file("http://www.google.com", gtmpfile)
# Remove tempfile when finished:
unlink(gtmpfile)

# Get weather data from Smith Island, at east end of Strait of
#   Juan de Fuca (Washington, USA).  Read the data into S-PLUS
#   and plot:
wtmpfile <- tempfile("weather")
download.file("http://www.ndbc.noaa.gov/data/realtime2/SISW1.txt",
    wtmpfile)
weatherDF <- read.table(wtmpfile, header=T)
plot(weatherDF$BARO, type="l")
# Remove tempfile when finished:
unlink(wtmpfile)