The cf_datatype
function is all that is required to select clifro
datatypes. This function can be called without any arguments that takes the user through interactive menus, otherwise the datatypes may be chosen programmatically if the menu options are known in advance. Whether the intention is to choose one datatype or many, this vignette details the various methods in choosing them.
Most applications involving the environmental data contained within the National Climate Database will require selection of more than one option for more than one datatype. This is where the true advantages in using the clifro
package become apparent.
Let us consider an application where we are now interested in hourly and 9am surface wind along with hourly and daily rainfall, hourly counts of lightning flashes and daily and hourly grass temperature extremes.
There are a few ways to choose all of these datatypes. Firstly, you could go through the menu options one by one, selecting the corresponding datatypes and options and saving the resulting datatypes as different R objects. A less laborious alternative is to create each of these datatypes without the menus. This does of course assume we know the selections at each branch of the datatype selection menus.
## dt.name dt.type dt.options dt.combo
## dt1 Wind Surface wind [HlyWind, 9amWind] knots
## dt.name dt.type dt.options dt.combo
## dt1 Precipitation Rain (fixed periods) [Daily , Hourly]
## dt.name dt.type dt.options dt.combo
## dt1 Weather Lightning [Ltng]
# Daily and hourly grass temperature extremes
temperatureExtremes.dt = cf_datatype(4, 2, c(5, 6))
temperatureExtremes.dt
# Note: only the surface wind datatype requires combo options
## dt.name dt.type dt.options dt.combo
## dt1 Temperature and Humidity Max_min_temp [DlyGrass, HlyGrass]
This results in 4 separate objects in R containing the datatypes and their corresponding options. If we were wanting to submit a query using all of these datatypes at once, having four separate datatypes is less than optimal. The following table shows the options for each of the menus that we are interested in.
Menu | Surface wind | Rainfall | Lightning | Temperature |
---|---|---|---|---|
First selection | 2 | 3 | 6 | 4 |
Second selection | 1 | 1 | 1 | 2 |
Third selection(s) | 2 & 4 | 1 & 2 | 1 | 5 & 6 |
combo box options | 3 | NA | NA | NA |
We can read across the columns to see the selections that are needed to return an R object containing the datatypes we are interested in. We can then just pass these values into the cf_datatype
function to return a single R object containing all of our datatypes and options.
query1.dt = cf_datatype(c(2, 3, 6, 4),
c(1, 1, 1, 2),
list(c(2, 4), c(1, 2), 1, c(5, 6)),
c(3, NA, NA, NA))
query1.dt
## dt.name dt.type dt.options dt.combo
## dt1 Wind Surface wind [HlyWind, 9amWind] knots
## dt2 Precipitation Rain (fixed periods) [Daily , Hourly]
## dt3 Weather Lightning [Ltng]
## dt4 Temperature and Humidity Max_min_temp [DlyGrass, HlyGrass]
We can also easily combine separate cfDatatype
objects in R using the addition symbol +
, to produce an identical result. This may be useful when you want to conduct multiple queries which include a subset of these datatypes.
## dt.name dt.type dt.options dt.combo
## dt1 Wind Surface wind [HlyWind, 9amWind] knots
## dt2 Precipitation Rain (fixed periods) [Daily , Hourly]
## dt3 Weather Lightning [Ltng]
## dt4 Temperature and Humidity Max_min_temp [DlyGrass, HlyGrass]
# To add another datatype using the menu:
query1.dt + cf_datatype()
# Is equivalent to:
query1.dt + cf_datatype(NA, NA, NA, NA)
# Therefore is equivalent to adding a column of NA's to the above table:
query1.dt = cf_datatype(c(2, 3, 6, 4, NA),
c(1, 1, 1, 2, NA),
list(c(2, 4), c(1, 2), 1, c(5, 6), NA),
c(3, NA, NA, NA, NA))
# Half an unknown wind datatype i.e. we know first selection = 2 but nothing
# further:
rain.dt = cf_datatype(2) # Or cf_datatype(2, NA, NA, NA)