dataDWD {rdwd} | R Documentation |
Download data from the DWD CDC FTP Server
Description
Get climate data from the German Weather Service (DWD) FTP-server.
The desired dataset is downloaded into dir
.
If read=TRUE
, it is also read and processed.
dataDWD
handles vectors of URLs,
displays progress bars (if the package pbapply
is available)
and by default does not re-download data already in dir
(but see argument force
to update files).
To solve "errors in download.file: cannot open URL", see
https://bookdown.org/brry/rdwd/fileindex.html.
Usage
dataDWD(
url,
base = dwdbase,
joinbf = FALSE,
dir = locdir(),
force = FALSE,
overwrite = !isFALSE(force),
read = TRUE,
dbin = TRUE,
method = getOption("download.file.method"),
dfargs = NULL,
sleep = 0,
progbar = !quiet,
browse = FALSE,
ntrunc = 2,
file = NULL,
quiet = rdwdquiet(),
...
)
Arguments
url |
Char (vector): complete file URL(s) (including base and filename.zip)
as returned by |
base |
Single char: base URL that will be removed from output file names.
DEFAULT: |
joinbf |
Logical: paste |
dir |
Char: Writeable directory name where to save the downloaded file.
Created if not existent. DEFAULT: |
force |
Logical (vector): always download, even if the file already exists in |
overwrite |
Logical (vector): if force=TRUE, overwrite the existing file
rather than append "_1"/"_2" etc to the filename?
DEFAULT: |
read |
Logical: read the file(s) with |
dbin |
Logical: Download binary file, i.e. add |
method |
download.file |
dfargs |
Named list of additional arguments passed to |
sleep |
Number. If not 0, a random number of seconds between 0 and
|
progbar |
Logical: present a progress bar with estimated remaining time?
If missing and length(file)==1, progbar is internally set to FALSE.
Only works if the R package |
browse |
Logical: open repository via |
ntrunc |
Single integer: number of filenames printed in messages before they get truncated with message "(and xx more)". DEFAULT: 2 |
file |
Deprecated since rdwd version 1.3.34, 2020-07-28. |
quiet |
Logical: suppress message about directory / filenames?
DEFAULT: FALSE through |
... |
Further arguments passed to |
Value
Presuming downloading and processing were successful:
if read=TRUE
, the desired dataset
(as returned by readDWD()
),
otherwise the filename as saved on disc
(may have "_n" appended in name, see newFilename()
).
If length(file)>1, the output is a list of outputs / vector of filenames.
The output is always invisible.
Author(s)
Berry Boessenkool, berry-b@gmx.de, Jun-Oct 2016
See Also
selectDWD()
. readDWD()
, download.file()
.
https://bookdown.org/brry/rdwd
Helpful for plotting: berryFunctions::monthAxis()
,
see also berryFunctions::climateGraph()
Examples
## Not run: ## requires internet connection
# find FTP files for a given station name and file path:
link <- selectDWD("Fuerstenzell", res="hourly", var="wind", per="recent")
# download file:
fname <- dataDWD(link, dir=locdir(), read=FALSE) ; fname
# dir="DWDdata" is the default directory to store files
# unless force=TRUE, already obtained files will not be downloaded again
# read and plot file:
wind <- readDWD(fname, varnames=TRUE) ; head(wind)
metafiles <- readMeta(fname) ; str(metafiles, max.level=1)
column_names <- readVars(fname) ; head(column_names)
plot(wind$MESS_DATUM, wind$F, main="DWD hourly wind Fuerstenzell", col="blue",
xaxt="n", las=1, type="l", xlab="Date", ylab="Hourly Wind speed [m/s]")
berryFunctions::monthAxis(1)
# current and historical files, keep historical in the overlap time period:
link <- selectDWD("Potsdam", res="daily", var="kl", per="hr"); link
potsdam <- dataDWD(link, dir=locdir(), hr=4)
plot(TMK~MESS_DATUM, data=tail(potsdam,1500), type="l")
# With many files (>>50), use sleep to avoid getting kicked off the FTP server
#links <- selectDWD(res="daily", var="solar")
#sol <- dataDWD(links, sleep=20) # random waiting time after download (0 to 20 secs)
# Real life examples can be found in the use cases section of the vignette:
# browseURL("https://bookdown.org/brry/rdwd")
## End(Not run)