Skip to contents

Function to set, rename or unset by reference the "idfactor" attribute of an existing object of class generic_spct or an object of a class derived from generic_spct.

Usage

setIdFactor(x, idfactor)

id_factor(x) <- value

Arguments

x

a generic_spct object.

idfactor, value

character The name of a factor identifying multiple spectra stored longitudinally.

Value

x

Details

If the attribute idfactor is already set, and a variable with name equal to the value passed as argument to idfactor does not exist in x, the currently set variable is renamed and the attribute value updated. If a variable named as the argument passed to idfactor exists in x, it will be set as id by storing this name in the attribute. If the value passed as argument to idfactor is NULL the attribute will be unset. If the attribute is not already set and there is no member variable in x with a name matching the argument passed to idfactor, an error is triggered.

Note

This function alters x itself by reference and in addition returns x invisibly. If x is not a generic_spct or an object of a class derived from generic_spct, x is not modified.

See also

Other idfactor attribute functions: getIdFactor()

Examples

my.spct <- sun_evening.spct

# inspecting
id_factor(sun.spct) # no idfactor set
#> [1] NA

id_factor(my.spct)
#> [1] "spct.idx"
colnames(my.spct)
#> [1] "w.length"  "s.e.irrad" "spct.idx" 

# renaming
id_factor(my.spct) <- "time"
getIdFactor(my.spct)
#> [1] "time"
colnames(my.spct)
#> [1] "w.length"  "s.e.irrad" "time"     

# removing
setIdFactor(my.spct, NULL)
getIdFactor(my.spct)
#> [1] NA
colnames(my.spct)
#> [1] "w.length"  "s.e.irrad" "time"