[R] New unique name

Barry Rowlingson B.Rowlingson at lancaster.ac.uk
Mon Apr 19 13:31:44 CEST 2004

(Ted Harding) wrote:

> A bit sledgehammer for nut, but as least it meets your needs!

  You could even use uuidgen to create a universally unique ID, and then 
use make.names to R-ify it:

 > make.names(system("uuidgen",intern=T))
[1] "aa33d26c.88a5.4eab.94ba.5073c4718ffe"
 > make.names(system("uuidgen",intern=T))
[1] "d5aea7a0.81e9.4690.8d48.d74fd2b50a83"
 > make.names(system("uuidgen",intern=T))
[1] "X2570d3e0.6b07.42be.a9c6.3701ac82b4f0"

  Of course the requirement was to make an object with a name that 
didn't already exist, and there's no guarantee that you haven't already 
created an object called "X2570d3e0.6b07.42be.a9c6.3701ac82b4f0" for 
some reason.

  So that's no good.

  How about getting an alphabetically-sorted list of all the current 
objects and then using the last one augmented with something:

makeUnique <- function(){

  I'm sure someone can come up with a bigger sledgehammer, or a reason 
why this wont always be unique. What's the longest name of an object in 
R? That'll break it... Pah.


More information about the R-help mailing list