Advanced Use Cases

Koen Hufkens

2020-07-13

Advanced Use Cases

This is a brief overview of some of the more advanced options in the ecmwfr package.

Setup

A ‘hidden’ feature of the wf_set_key() function is that it returns the user name upon success. This allows for easier integration in scripts shared with users (which have different credentials)

Formatting requests

The conversion from a MARS or python based queries (formed on the ECMWF or Copernicus CDS websites) to the list format used by ecmwfr can be automated if you use the RStudio based Addin.

By selecting and using Addin -> Mars to list (or ‘Python to list’) you dynamically convert queries copied from either ECMWF or CDS based services.

Using the Addin is the sure way to form a proper ecmwfr request and avoids typos. As such, we recommend the use of the Addin.

Piped requests

Another hidden feature of ecmwfr is the fact that the request is the first argument in the wf_request() function. This means that any valid list can be piped into this function (using the %>% or pipe symbol).

Dynamic request functions / archetypes

Once a valid request has been created it can be made into a dynamic function using achetypes. Archetype functions are build using a valid ecmwfr ECMWF or CDS request and the vector naming the field which are to be set as dynamic.

The wf_archetype() function creates a new function with as parameters the dynamic fields previously assigned. The below example show how to use the function to generate the custom dynamic_request() function. We then use this new function to alter the area and date fields and pipe (%>%) into the wf_request() function to retrieve the data.