The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.

rcdo

Lifecycle: stable CRAN status

rcdo is a wrapper around Climate Data Operators.

Installation

You can install rcdo from CRAN with

install.packages("rcdo")

or the development version of rcdo from GitHub with:

# install.packages("pak")
pak::pak("eliocamp/rcdo")

Most operators are supported and are partially documented. The functions start with cdo_ an the name of the operator (e.g. the selname operator is the cdo_selname() function)

Example

library(rcdo)
cdo_use("packaged")  # use package version of cdo that can be installed with `cdo_install()`. 
#> Using packaged CDO, version 2.5.1.
ncep <- "hgt_ncep.nc"

The ymonmean operator computes monthly annual cycle. The rcdo function is cdo_ymonmean()

ncep |> 
  cdo_ymonmean() 
#> CDO command:
#>    /home/user1/.local/share/R/rcdo/cdo-2.5.1/bin/cdo ymonmean [ '/home/user1/Documents/r-packages/rcdo/hgt_ncep.nc' ] {{output}}

The output just prints the command with a place holder output. Use cdo_execute() to actually run the command. If no outpuf file is specified, then the result is saved in a tempfile.

ncep |> 
  cdo_ymonmean() |> 
  cdo_execute()
#> [1] "/tmp/RtmpCwYLc5/file11103679d9d408"
#> attr(,"ephemeral")
#> attr(,"ephemeral")[[1]]
#> File will be deleted when garbage collected
#> 
#> attr(,"mtime")
#> [1] "2025-05-14 10:42:16 AEST"
#> attr(,"size")
#> [1] 8630649

Operators can be chained. Lets select just the Southern Hemisphere first.

ncep |> 
  cdo_sellonlatbox(lon1 = 0, lon2 = 360, lat1 = -90, lat2 = 0) |> 
  cdo_ymonmean() 
#> CDO command:
#>    /home/user1/.local/share/R/rcdo/cdo-2.5.1/bin/cdo ymonmean [ -sellonlatbox,0,360,-90,0 [ '/home/user1/Documents/r-packages/rcdo/hgt_ncep.nc' ] ] {{output}}

Now also select the 500 hPa level

ncep |> 
  cdo_sellonlatbox(lon1 = 0, lon2 = 360, lat1 = -90, lat2 = 0) |> 
  cdo_sellevel(level = 500) |> 
  cdo_ymonmean() 
#> CDO command:
#>    /home/user1/.local/share/R/rcdo/cdo-2.5.1/bin/cdo ymonmean [ -sellevel,500 [ -sellonlatbox,0,360,-90,0 [ '/home/user1/Documents/r-packages/rcdo/hgt_ncep.nc' ] ] ] {{output}}
ncep |> 
  cdo_sellonlatbox(lon1 = 0, lon2 = 360, lat1 = -90, lat2 = 0) |> 
  cdo_sellevel(level = 500) |> 
  cdo_ymonmean() 
#> CDO command:
#>    /home/user1/.local/share/R/rcdo/cdo-2.5.1/bin/cdo ymonmean [ -sellevel,500 [ -sellonlatbox,0,360,-90,0 [ '/home/user1/Documents/r-packages/rcdo/hgt_ncep.nc' ] ] ] {{output}}

Prior art

The ClimateOperators package also wrapps CDO, but it’s approach is different. Instead of wrapping each operator as its own function with parameters as arguments, it provides a generic cdo() function that runs the operators that the user needs to write as strings. Instead of

ncep |> 
  rcdo::cdo_sellonlatbox(lon1 = 0, lon2 = 360, lat1 = -90, lat2 = 0) 

one would write

ClimateOperators::cdo("sellonlatbox,0,360,-90,0", ncep, output_file)

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.