Learn R Programming

rdwd (version 1.8.0)

selectDWD: Select data from the DWD CDC FTP Server

Description

Select data files for downloading with dataDWD().
The available res/var/per folders with datasets are listed online.
Set res="", var="", per="" to avoid the default interactive selection.
The arguments name/id and res/var/per can be vectors.

Usage

selectDWD(
  name = "",
  res = NA,
  var = NA,
  per = NA,
  expand = TRUE,
  id = findID(name, exactmatch = exactmatch, mindex = mindex, quiet = quiet, failempty =
    failempty),
  exactmatch = TRUE,
  mindex = metaIndex,
  failempty = TRUE,
  findex = fileIndex,
  current = FALSE,
  base = dwdbase,
  meta = FALSE,
  quiet = rdwdquiet(),
  ...
)

Value

Character string with file path and name(s) in the format "base/res/var/per/filename.zip"

Arguments

name

Char: station name(s) passed to findID(), along with exactmatch, mindex and failempty. All 3 arguments are ignored if id is given. DEFAULT: "" (all stations at res/var/per)

res

Char: temporal resolution at base, e.g. "hourly","daily","monthly". See section 'Description' above and fileIndex. Use res="" for matching options from all resolutions. DEFAULT: NA for interactive selection

var

Char: weather variable of interest, e.g. "air_temperature", "cloudiness", "precipitation", "solar", "kl". See section 'Description' above and fileIndex. DEFAULT: NA for interactive selection

per

Char: desired time period, e.g. "recent" (up to date records from the last 1.5 years) or "historical" (long time series). Can be abbreviated. To get both datasets, use per="hr". DEFAULT: NA for interactive selection

expand

Logical: get all possible res/var/per combinations? Set to FALSE if you want only the given combinations. If FALSE, they cannot be NA or "". DEFAULT: TRUE

id

Char/Number: station ID with or without leading zeros, e.g. "00614" or 614. Is internally converted to an integer. Use NA (the default from findID) to get all data at res/var/per. DEFAULT: findID(name, exaxtmatch, mindex, failempty)

exactmatch

Logical passed to findID(): match name with ==)? Else with grepl(). DEFAULT: TRUE

mindex

Single object: Index with metadata passed to findID(). DEFAULT: metaIndex

failempty

Fail if no matching station is found in findID()? Avoid downloading all files. DEFAULT: TRUE

findex

Single object: Index used to select filename, as returned by createIndex().To use a current / custom index, see current and https://bookdown.org/brry/rdwd/fileindex.html. DEFAULT: fileIndex

current

Single logical when res/var/per is given: instead of findex, use a list of the currently available files at base/res/var/per? This will call indexFTP(), thus requires availability of the RCurl package. See https://bookdown.org/brry/rdwd/fileindex.html. DEFAULT: FALSE

base

Single char: main directory of DWD ftp server. Must be the same base used to create findex. DEFAULT: dwdbase

meta

Logical: select Beschreibung file from ismeta entries in findex? See metaIndex for a compilation of all Beschreibung files. See the 'Examples' section for handling pdf and txt files. DEFAULT: FALSE

quiet

Suppress id length warnings? DEFAULT: FALSE through rdwdquiet()

...

Further arguments passed to indexFTP() if current=TRUE, except folder and base.

Author

Berry Boessenkool, berry-b@gmx.de, Oct 2016, rewritten May 2022

See Also

dataDWD(), metaIndex, website station selection chapter

Examples

Run this code
# Give weather station name (must exist in metaIndex):
selectDWD("Potsdam", res="daily", var="kl", per="historical")

# all files for all stations matching "Koeln":
tail(selectDWD("Koeln", res="", var="", per="", exactmatch=FALSE)) # 686 files
findID("Koeln", FALSE)

if (FALSE)  # Excluded from CRAN checks to save time

# selectDWD("Potsdam") # interactive selection of res/var/per

# directly give station ID:
selectDWD(id="00386", res="daily", var="kl", per="historical")
selectDWD(id=537, "", "", "", "") # 8 files

# period can be abbreviated:
selectDWD(id="5419", res="daily", var="kl", per="h")

# selectDWD is vectorizable!
# since version 1.5.28 (2022-05-12) outer product, not elementwise comparison:
selectDWD("Freiburg", res="daily", var="kl", per="rh")
selectDWD("Freiburg", res=c("daily","monthly"), var="kl", per="r")
selectDWD("Freiburg", res=c("daily","monthly"), var="kl", per="hr")
# get old behaviour (needed e.g. in nearbyStations):
ids <- c(3761,3761, 3603)
# all combinations:
selectDWD(id=ids, res="daily", var="kl", per=c("h","r","r")) # 4
# only given combinations:
selectDWD(id=ids, res="daily", var="kl", per=c("h","r","r"), expand=FALSE) # 3

# all files in all paths matching id:
head( selectDWD(id=c(1050, 386), res="",var="",per="") ) # 277 files
# all files in a given path (if ID is empty):
head(  selectDWD(id="", res="daily", var="kl", per="recent")   ) # 585 files

selectDWD(id=386, res="monthly", var="kl", per="h")

# Meta  data - Description and Beschreibung txt/pdf files.:
# manually select .txt (not pdf) files for automated opening with readDWD.
link <- selectDWD(res="monthly", var="kl", per="h", meta=TRUE) # omit ID/Name!
link
link2 <- grep("\\.txt$", link, value=TRUE)   ;   link2
m <- dataDWD(link2, dir=locdir())
head(m)
# 
# Open PDF files with your system's default Viewer:
dataDWD(link[1], dir=locdir())


Run the code above in your browser using DataLab