Skip to contents

rcdo is a wrapper around Climate Data Operators.

Installation

You can install rcdo from CRAN with

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()`. 
ncep <- "hgt_ncep.nc"

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

ncep |> 
  cdo_ymonmean() 

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

ncep |> 
  cdo_ymonmean() |> 
  cdo_execute()

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

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

Now also select the 500 hPa level

ncep |> 
  cdo_sellonlatbox(lon1 = 0, lon2 = 360, lat1 = -90, lat2 = 0) |> 
  cdo_sellevel(level = 500) |> 
  cdo_ymonmean() 
ncep |> 
  cdo_sellonlatbox(lon1 = 0, lon2 = 360, lat1 = -90, lat2 = 0) |> 
  cdo_sellevel(level = 500) |> 
  cdo_ymonmean() 

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)