Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add new slot to already existing class?

I have variable mod of class unmarkedFitPCount from package unmarked and I need to add a new attribute to that class:

mod@new_attr <- 1

I get an error:

‘new_attr’ is not a slot in class “unmarkedFitPCount”

I need to add this new attribute without creating a new derived class, because I need all those functions to work on this object. This is supposed to be just a very lightweight temporary hack. How can I do that?

like image 272
Tomas Avatar asked Jul 08 '16 11:07

Tomas


1 Answers

What about: attributes(mod)$new_attr <- 1.

The core function attributes accesses an object's attributes. In this example you create a new attribute new_attr and assign it the value of 1.

You can then access the newly created attribute via attributes(mod)$new_attr.

like image 75
timothyjgraham Avatar answered Nov 04 '22 11:11

timothyjgraham