In some languages there is a function gensym() which returns a new unique name (in the current environment). This is quite helpful when one has to do temporary assignments. I could not find such a function in R. Is there one? -- Erich Neuwirth, Computer Supported Didactics Working Group Visit our SunSITE at http://sunsite.univie.ac.at Phone: +43-1-4277-38624 Fax: +43-1-4277-9386
On Mon, 19 Apr 2004, Erich Neuwirth wrote:> In some languages there is a function > gensym() > which returns a new unique name (in the current environment). > This is quite helpful when one has to do temporary assignments. > I could not find such a function in R. > Is there one?Not that I know of. `In the current environment' is problematic, since R has many environments and lexical scoping so different functions can have different environments. It's better to pick your own: ErichNeuwirth190404a looks unlikely to be used by anyone else! basename(tempfile("ENeuwirth")) also looks like a good start. Normally this is done within the body of a function, and all one needs to do is to choose a symbol name not used in that function (although we do see occasional problem with the use of `x' causing masking). An alternative is to use a nested function for the computations, or to set up a temporary environment (most conveniently via local()). (If perchance you meant the local frame, then using local() is the R equivalent.) -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
On 19-Apr-04 Erich Neuwirth wrote:> In some languages there is a function > gensym() > which returns a new unique name (in the current environment). > This is quite helpful when one has to do temporary assignments. > I could not find such a function in R. > Is there one?If you are running R on a Unix-like system (such as Linux) then you could use the "mktemp" function (see 'man mktemp'). In R, system("mktemp -u tmpXXXXXX") will return a unique identifier (and will not, because of the "-u" flag, create the file). The identifier will be of the form (e.g.) "tmpdPT6Nw", i.e. with the 6 X's replaced by random characters. A bit sledgehammer for nut, but as least it meets your needs! (Strictly speaking, uniqueness in repeated use is not absolutely guaranteed with the "-u" option, since strict uniqueness depends on 'mktemp' checking for an existing file with the same name. However, since there are some (26+26+10)^6 > 10^10 combinations to randomly choose from, you should be pretty safe.) Best wishes, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk> Fax-to-email: +44 (0)870 167 1972 Date: 19-Apr-04 Time: 12:00:35 ------------------------------ XFMail ------------------------------
One possibility would be the Ruuid library in BioConductor. I'm not sure if the uuid library is available (or compilable) under MS Windows, though. I'll be checking in a bit (weeks) if no one else does. Erich Neuwirth <erich.neuwirth at univie.ac.at> writes:> In some languages there is a function > gensym() > which returns a new unique name (in the current environment). > This is quite helpful when one has to do temporary assignments. > I could not find such a function in R. > Is there one? > > > -- > Erich Neuwirth, Computer Supported Didactics Working Group > Visit our SunSITE at http://sunsite.univie.ac.at > Phone: +43-1-4277-38624 Fax: +43-1-4277-9386 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- rossini at u.washington.edu http://www.analytics.washington.edu/ Biomedical and Health Informatics University of Washington Biostatistics, SCHARP/HVTN Fred Hutchinson Cancer Research Center UW (Tu/Th/F): 206-616-7630 FAX=206-543-3461 | Voicemail is unreliable FHCRC (M/W): 206-667-7025 FAX=206-667-4812 | use Email CONFIDENTIALITY NOTICE: This e-mail message and any attachme...{{dropped}}