Add a Class to an Object
add_class.Rd
Utility to prepend a new class(es) to existing objects.
Examples
class(iris)
#> [1] "data.frame"
add_class(iris, "new") |> class()
#> [1] "new" "data.frame"
add_class(iris, c("A", "B")) |> class() # 2 classes
#> [1] "A" "B" "data.frame"
add_class(iris, c("A", "data.frame")) |> class() # no duplicates
#> [1] "A" "data.frame"
add_class(iris, c("data.frame", "A")) |> class() # re-orders if exists
#> [1] "data.frame" "A"