Skip to contents

Check whether the names of trigonometric terms are used in a character vector or formula. A name is a trigonometric term if it is obtained by pasting "cosj" or "sinj" with an integer giving the harmonic. We expect that when a trigonometric "cosj" or "sinj" is found, it companion "sinj" or "cosj" is also found.

Usage

checkTrigNames(names)

Arguments

names

A character vector containing names of variables, possibly embeding trigonometric variables. Can also be a formula from which the names are extracted.

Value

The positive integer K such that the names

"cosj1", "sinj1", ..., "cosjK",

"sinjK" are found in name. If no trigonometric term is found then the value 0 is returned.

Caution

This fonction is likely to be come an internal (non-exported) function. Mind the 'j' in "cosj" os "sinj".

Examples

nm <- c("Cst", "sinj1", "cosj1", "sinj2", "cosj2", "sinj3", "cosj3")
checkTrigNames(nm)
#> [1] 3
## error: no 'sin' companion
try(checkTrigNames(c("Cst", "cosj1")))
#> Error in checkTrigNames(c("Cst", "cosj1")) : 
#>   Expect to find cos AND sin names or none of these
## Missing 'j': no trigonometric term
checkTrigNames(c("Cst", "cos1"))
#> [1] 0
checkTrigNames(c("Cst", "Prec"))
#> [1] 0