# Download CDS ERA5 data using R

**URL:** <https://forum.ecmwf.int/t/download-cds-era5-data-using-r/1365>\
**Category:** C3S - Access and Login\
**Tags:** access, c3s, era5\
**Created:** [1 April 2021 10:33 UTC](https://forum.ecmwf.int/t/download-cds-era5-data-using-r/1365 "2021-04-01T10:33:03Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin\_Marsh](https://forum.ecmwf.int/user_avatar/forum.ecmwf.int/kevin_marsh/32/368_2.png) [@Kevin\_Marsh](https://forum.ecmwf.int/u/Kevin_Marsh)\
**Post date:** [1 April 2021 10:33 UTC](https://forum.ecmwf.int/t/download-cds-era5-data-using-r/1365/1 "2021-04-01T10:33:03Z")

</div>

Users can download CDS data using the&nbsp;[ecmwfr](https://cran.r-project.org/web/packages/ecmwfr/index.html) package&nbsp;in R with&nbsp;“cds” as the "service" although it is not supported by C3S. In the examples below, "KEY" and "UID" are your CDS API key and UID respectively.

**PLEASE NOTE THAT SINCE THE MOVE TO THE NEW CDS IN OCTOBER 2024, "UID" IS NO LONGER REQUIRED BY THE CDS API.   
-YOU SHOULD THEREFORE MAKE SURE THAT YOUR R PACKAGE TAKES THIS CHANGE INTO ACCOUNT AND IS UP TO DATE**

Please have a look at the following example to download ERA5 2m temperature for a selected area in netCDF format:&nbsp;

| 

`library(ecmwfr)`  
 &nbsp;  
`cds.key <- ``"Insert_your_CDS_API_KEY_here"`  
`wf_set_key(user = ``"Insert_your_CDS_UID_here"``, key = cds.key, service = ``"cds"``)`  
 &nbsp;  
`request <- list(`  
`dataset_short_name = ``"reanalysis-era5-single-levels"``,`  
`product_type   = ``"reanalysis"``,`  
`format = ``"netcdf"``,`  
`variable = ``"2m_temperature"``,`  
`year = ``"2016"``,`  
`month = ``"08"``,`  
`day = ``"16"``,`  
`time = c(``"00:00"``, ``"01:00"``, ``"02:00"``, ``"03:00"``, ``"04:00"``, ``"05:00"``, ``"06:00"``, ``"07:00"``, ``"08:00"``, ``"09:00"``, ``"10:00"``, ``"11:00"``, ``"12:00"``, ``"13:00"``, ``"14:00"``, ``"15:00"``, ``"16:00"``, ``"17:00"``, ``"18:00"``, ``"19:00"``, ``"20:00"``, ``"21:00"``, ``"22:00"``, ``"23:00"``),`  
`# area is specified as N, W, S, E`  
`area = c(``50``, -``20``, ``30``, ``20``),`  
`target = ``"download_e5_single.nc"`  
`)`  
 &nbsp;  
`file <- wf_request(user = ``"Insert_your_CDS_UID_here"``,`  
`                     ``request = request,`  
`                     ``transfer = TRUE,`  
`                     ``path = ``"~"``,`  
`                     ``verbose = TRUE)`

 |

This would return the data to a file called&nbsp;[download\_e5\_single.nc](http://download_e5_single.nc).

The code below retrieves ERA5pressure level temperature data at 850hpa for a selected area in netCDF format:

| 

`library(ecmwfr)`  
 &nbsp;  
`cds.key <- ``"Insert_your_CDS_API_KEY_here"`  
`wf_set_key(user = ``"Insert_your_CDS_UID_here"``, key = cds.key, service = ``"cds"``)`  
 &nbsp;  
`request <- list(`  
`dataset_short_name = ``"reanalysis-era5-pressure-levels"``,`  
`product_type   = ``"reanalysis"``,`  
`format = ``"netcdf"``,`  
`variable = ``"temperature"``,`  
`pressure_level = ``"850"`  
`year = ``"2016"``,`  
`month = ``"08"``,`  
`day = ``"16"``,`  
`time = c(``"00:00"``, ``"01:00"``, ``"02:00"``, ``"03:00"``, ``"04:00"``, ``"05:00"``, ``"06:00"``, ``"07:00"``, ``"08:00"``, ``"09:00"``, ``"10:00"``, ``"11:00"``, ``"12:00"``, ``"13:00"``, ``"14:00"``, ``"15:00"``, ``"16:00"``, ``"17:00"``, ``"18:00"``, ``"19:00"``, ``"20:00"``, ``"21:00"``, ``"22:00"``, ``"23:00"``),`  
`# area is specified as N, W, S, E`  
`area = c(``50``, -``20``, ``30``, ``20``),`  
`target = ``"download_e5_pressure.nc"`  
`)`  
 &nbsp;  
`file <- wf_request(user = ``"Insert_your_CDS_UID_here"``,`  
`                     ``request = request,`  
`                     ``transfer = TRUE,`  
`                     ``path = ``"~"``,`  
`                     ``verbose = TRUE)`

 |

---

<div class="post-metadata">

**Author:** ![Malcolm\_Mistry](https://forum.ecmwf.int/letter_avatar_proxy/v4/letter/m/dec6dc/32.png) [@Malcolm\_Mistry](https://forum.ecmwf.int/u/Malcolm_Mistry)\
**Post date:** [25 August 2021 16:12 UTC](https://forum.ecmwf.int/t/download-cds-era5-data-using-r/1365/2 "2021-08-25T16:12:17Z")

</div>

Thanks. This really helps. Just wondering, is there a way to pass the 'area' argument (to subset the data by bounding box) for those datasets that are not on a regular lon lat grid. Example [UERRA](https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-uerra-europe-pressure-levels?tab=form) dataset which is on a Lambert Conformal Conic grid. For such datasets, the 'Geographical area' option does not appear when selecting/filtering the variable. I see there is a related question [here](https://prod.ecmwf-forum-prod.compute.cci2.ecmwf.int/t/how-to-sub-region-extraction-of-thermal-comport-indices-data-by-cdsapi/908) (though this question in fact is for another dataset that is already on a regular lon lat grid, yet not available to subset the bounding box). I am not sure why it would be difficult to transform the user defined regular lon lat coordinates to the dataset's native projection on the back-end, i.e. the Show API request should be able to do this in the background and display the 'area' coordinates for subsetting.

---

<div class="post-metadata">

**Author:** ![Kevin\_Marsh](https://forum.ecmwf.int/user_avatar/forum.ecmwf.int/kevin_marsh/32/368_2.png) [@Kevin\_Marsh](https://forum.ecmwf.int/u/Kevin_Marsh)\
**Post date:** [31 August 2021 21:21 UTC](https://forum.ecmwf.int/t/download-cds-era5-data-using-r/1365/3 "2021-08-31T21:21:24Z")

</div>

Hi Malcolm,

No, at this time I don't think it is possible to perform an area subset in the way you describe using the CDS API, but it is a good suggestion for a future development,

Thanks,

Kevin&nbsp;

---

<div class="post-metadata">

**Author:** ![Malcolm\_Mistry](https://forum.ecmwf.int/letter_avatar_proxy/v4/letter/m/dec6dc/32.png) [@Malcolm\_Mistry](https://forum.ecmwf.int/u/Malcolm_Mistry)\
**Post date:** [1 September 2021 03:37 UTC](https://forum.ecmwf.int/t/download-cds-era5-data-using-r/1365/4 "2021-09-01T03:37:57Z")

</div>

Hi Kevin,

Thanks again!&nbsp;

Rgds

Malcolm

---

<div class="post-metadata">

**Author:** ![Amaury\_Alloyer](https://forum.ecmwf.int/letter_avatar_proxy/v4/letter/a/7ba0ec/32.png) [@Amaury\_Alloyer](https://forum.ecmwf.int/u/Amaury_Alloyer)\
**Post date:** [26 April 2024 13:59 UTC](https://forum.ecmwf.int/t/download-cds-era5-data-using-r/1365/5 "2024-04-26T13:59:38Z")

</div>

Hi Kevin, thank you, that helped a lot. Do you know if we ca use “ecmwfr” R package to download cmip6 projections ?  
Best,

---

<div class="post-metadata">

**Author:** ![Kevin\_Marsh](https://forum.ecmwf.int/user_avatar/forum.ecmwf.int/kevin_marsh/32/368_2.png) [@Kevin\_Marsh](https://forum.ecmwf.int/u/Kevin_Marsh)\
**Post date:** [6 June 2024 14:48 UTC](https://forum.ecmwf.int/t/download-cds-era5-data-using-r/1365/6 "2024-06-06T14:48:42Z")

</div>

Hi, ‘ecmwfr’ is a 3rd party package, and I’m afraid I don’t know if it would work with CDS cmip6 projection data.  
Kevin

---

<div class="post-metadata">

**Author:** ![Charles\_Ramos](https://forum.ecmwf.int/user_avatar/forum.ecmwf.int/charles_ramos/32/502_2.png) [@Charles\_Ramos](https://forum.ecmwf.int/u/Charles_Ramos)\
**Post date:** [29 July 2024 07:13 UTC](https://forum.ecmwf.int/t/download-cds-era5-data-using-r/1365/7 "2024-07-29T07:13:57Z")

</div>

Hello Kevin. Since a new CDS has been launched, new credentials are already released. Should I use the 32-character ID for the _user_ field instead of the usual 6-digit ID?

I’ve tried it but there is an error.

![image](https://forum.ecmwf.int/uploads/default/optimized/1X/e0f52ed43de0d81a31753e2913734b63e248d3b5_2_690x39.png)

---

<div class="post-metadata">

**Author:** ![Kevin\_Marsh](https://forum.ecmwf.int/user_avatar/forum.ecmwf.int/kevin_marsh/32/368_2.png) [@Kevin\_Marsh](https://forum.ecmwf.int/u/Kevin_Marsh)\
**Post date:** [30 July 2024 10:28 UTC](https://forum.ecmwf.int/t/download-cds-era5-data-using-r/1365/8 "2024-07-30T10:28:12Z")

</div>

Hi Charles,

if you login to CDS-beta and go to  
[https://cds-beta.climate.copernicus.eu/how-to-api](https://cds-beta.climate.copernicus.eu/how-to-api)  
you should see your CDS-beta login credentials (note there is no longer a ‘UID’).

I do not know if the ecmwfr package will handle these details correctly.

---

<div class="post-metadata">

**Author:** ![Koen\_Hufkens](https://forum.ecmwf.int/user_avatar/forum.ecmwf.int/koen_hufkens/32/526_2.png) [@Koen\_Hufkens](https://forum.ecmwf.int/u/Koen_Hufkens)\
**Post date:** [21 August 2024 09:31 UTC](https://forum.ecmwf.int/t/download-cds-era5-data-using-r/1365/9 "2024-08-21T09:31:46Z")

</div>

Hi Charles, an update to the package is in the works. For now this will only use the old CDS/ADS setup. I’m roughly a week away from a formal release.

---

<div class="post-metadata">

**Author:** ![Koen\_Hufkens](https://forum.ecmwf.int/user_avatar/forum.ecmwf.int/koen_hufkens/32/526_2.png) [@Koen\_Hufkens](https://forum.ecmwf.int/u/Koen_Hufkens)\
**Post date:** [15 December 2024 09:08 UTC](https://forum.ecmwf.int/t/download-cds-era5-data-using-r/1365/10 "2024-12-15T09:08:42Z")

</div>

To update this thread, a new version of {ecmwfr} for R is available and inline with the current API here:

> **[Interface to ECMWF and CDS Data Web Services](https://bluegreen-labs.github.io/ecmwfr/)**
>
> Programmatic interface to the European Centre for Medium-Range Weather Forecasts dataset web services (ECMWF; ) and Copernicus's Data Stores. Allows for easy downloads of weather forecasts and climate reanalysis data in R. Data stores covered include...

---

<div class="post-metadata">

**Author:** ![Charles\_Ramos](https://forum.ecmwf.int/user_avatar/forum.ecmwf.int/charles_ramos/32/502_2.png) [@Charles\_Ramos](https://forum.ecmwf.int/u/Charles_Ramos)\
**Post date:** [18 December 2024 02:34 UTC](https://forum.ecmwf.int/t/download-cds-era5-data-using-r/1365/11 "2024-12-18T02:34:59Z")

</div>

Thanks for this, Koen!

---

<div class="post-metadata">

**Author:** ![Alexander\_Kaune](https://forum.ecmwf.int/letter_avatar_proxy/v4/letter/a/eb9ed0/32.png) [@Alexander\_Kaune](https://forum.ecmwf.int/u/Alexander_Kaune)\
**Post date:** [12 December 2025 12:55 UTC](https://forum.ecmwf.int/t/download-cds-era5-data-using-r/1365/12 "2025-12-12T12:55:21Z")

</div>

Thanks Koen, this new version of {ecmwfr} for R is still valid? For the following code in R I’m getting “❌ Test failed: Data identifier reanalysis-era5-land is not found in Web API, CDS or ADS datasets.\n Or your login credentials do not match your request.”

Minimal test script for CDS connection

library(ecmwfr)

# Set key with validation disabled (if available)

tryCatch({

# Try to set key with current .cdsapirc contents

config\_path ← “C:/Users/alexk/.cdsapirc”  
if(file.exists(config\_path)) {  
lines ← readLines(config\_path, warn = FALSE)  
key\_line ← grep(“^key:”, lines, value = TRUE)  
if(length(key\_line) \> 0) {  
api\_key ← trimws(sub(“^key:\s\*”, “”, key\_line))

```auto
  # Try without validate parameter first
  wf_set_key(key = api_key, service = "cds")
  print("✅ Key set successfully")
}

```

}  
}, error = function(e) {  
print(paste(“Setting key failed:”, e$message))  
})

# Test request

test\_request ← list(  
dataset\_short\_name = “reanalysis-era5-land”,  
product\_type = “reanalysis”,  
variable = “2m\_temperature”,  
year = “2020”,  
month = “01”,  
day = “01”,  
time = “00:00”,  
area = c(10, -86, 9, -85), # Small area in Costa Rica  
format = “netcdf”,  
target = “test.nc”  
)

print(“Testing download…”)  
tryCatch({  
result ← wf\_request(request = test\_request, time\_out = 300, path = temp\_dir)  
print(“✅ Test download successful!”)  
}, error = function(e) {  
print(paste(“❌ Test failed:”, e$message))  
})

---

<div class="post-metadata">

**Author:** ![Koen\_Hufkens](https://forum.ecmwf.int/user_avatar/forum.ecmwf.int/koen_hufkens/32/526_2.png) [@Koen\_Hufkens](https://forum.ecmwf.int/u/Koen_Hufkens)\
**Post date:** [14 December 2025 18:38 UTC](https://forum.ecmwf.int/t/download-cds-era5-data-using-r/1365/13 "2025-12-14T18:38:49Z")

</div>

Your request passes on my end, but required formatting the quotation marks around entries correctly. Always use the rstudio plugin to convert the python API requests to the R version, manually editting things often leads to hard to trace errors.
