This function can be used to download a file from the Internet.
download.file(url, destfile, method, quiet = FALSE, mode = "w", cacheOK = TRUE, extra = getOption("download.file.extra"))
- A character string naming the URL of a resource to be downloaded.
- A character string with the name where the downloaded file is saved. Tilde-expansion is performed.
- Method to be used for downloading files. Currently download methods
"lynx"are available, and there is a value
"auto": see ‘Details’ and ‘Note’.
The method can also be set through the option
TRUE, suppress status messages (if any), and the progress bar.
- character. The mode with which to write the file. Useful values are
"ab". Only used for the
- logical. Is a server-side cached value acceptable? Implemented for the
- character vector of additional command-line arguments for the
cacheOK = FALSE is useful for http:// URLs, and will attempt to get a copy directly from the site rather than from an intermediate cache. (Not all platforms support it.) It is used by
The remaining details apply to method
Note that https:// URLs are not supported.
url for how file:// URLs are interpreted, especially on Windows. This function does decode encoded URLs.
The timeout for many parts of the transfer can be set by the option
timeout which defaults to 60 seconds.
The level of detail provided during transfer can be set by the
quiet argument and the
internet.info option. The details depend on the platform and scheme, but setting
internet.info to 0 gives all available details, including all server responses. Using 2 (the default) gives only serious messages, and 3 or more suppresses all messages.
"wget" can be used with proxy firewalls which require user/password authentication if proper values are stored in the configuration file for
An (invisible) integer code,
"lynx" methods this is the status code returned by the external program. The
"internal" method can return
1, but will in most cases throw an error.
This applies to the internal code only.
Proxies can be specified via environment variables. Setting "no_proxy" to
"*" stops any proxy being tried. Otherwise the setting of "http_proxy" or "ftp_proxy" (or failing that, the all upper-case version) is consulted and if non-empty used as a proxy site. For FTP transfers, the username and password on the proxy can be specified by "ftp_proxy_user" and "ftp_proxy_password". The form of "http_proxy" should be
"http://proxy.dom.com:8080/" where the port defaults to
80 and the trailing slash may be omitted. For "ftp_proxy" use the form
"ftp://proxy.dom.com:3128/" where the default port is
21. These environment variables must be set before the download code is first used: they cannot be altered later by calling
Usernames and passwords can be set for HTTP proxy transfers via environment variable http_proxy_user in the form
user:passwd. Alternatively, http_proxy can be of the form
"http://user:firstname.lastname@example.org:8080/" for compatibility with
wget. Only the HTTP/1.0 basic authentication scheme is supported.
"lynx" are mainly for historical compatibility, but they and
"lynx" a system call is made to the tool given by
method, and the respective program must be installed on your system and be in the search path for executables.
wget (http://www.gnu.org/software/wget/) is commonly installed on Unix-alikes (but not OS X). Windows binaries are available from Cygwin, gnuwin32 and elsewhere.
curl (http://curl.haxx.se/) is installed on OS X and commonly on Unix-alikes. Windows binaries are available at that URL.
options to set the
url for a finer-grained way to read data from URLs.
Contributed package RCurl provides more comprehensive facilities to download from URLs.
Documentation reproduced from R 3.0.1. License: GPL-2.