[R] UUIDgenerate() withn a s4 class produces the same uuid at each instance

Servet Ahmet Çizmeli Servet.Ahmet.Cizmeli at USherbrooke.ca
Wed Jun 8 14:24:14 CEST 2016


 

Hello 

When I create a new instance of an S4 class in R, I would like the newly
created object to have a unique id field. I try to achieve it through
UUIDgenerate() from the uuid package. The problem is that I obtain the
same UUID at every new object instance : 

library(uuid)
setClass("C",
 representation=representation(
 id = "character"
 ),
 prototype = prototype(
 id = UUIDgenerate(use.time = TRUE))
 )

 new("C")

An object of class "C" Slot "id": [1]
"1e07d7c2-2d71-11e6-b5e1-e1f59d8ccf09" 

new("C")

An object of class "C" Slot "id": [1]
"1e07d7c2-2d71-11e6-b5e1-e1f59d8ccf09" 

new("C")

An object of class "C" Slot "id": [1]
"1e07d7c2-2d71-11e6-b5e1-e1f59d8ccf09" 

Calling UUIDgenerate() successively at the R command line produces
different UUIDS each time. 

Where do I go wrong? 

Thanks 

Servet 

 
	[[alternative HTML version deleted]]



More information about the R-help mailing list