mauede at alice.it
2009-Aug-13 14:05 UTC
[R] how to get R interpreter to remember constant values without using any memory location
Maybe I expect too much from a non compiled language. Anyway, I wonder whether it is possible in R to set constant values without using any memory location that would take useless space bacause such values are not going to be changed along the program. It's just a way to assign a mnemnic name tos some constant values. For instance, I would like R interpreter to replace all occurrences of mnemonic "Monday" with the number 1, "Tuesday" with the number 2, "Wednesday with the number 3, and so on ... without having to assign such values to memory locations. Maybe environment variables are the way to go ? Thank you in advance for your advice, Maura tutti i telefonini TIM! [[alternative HTML version deleted]]
Philipp Pagel
2009-Aug-13 14:55 UTC
[R] how to get R interpreter to remember constant values without using any memory location
On Thu, Aug 13, 2009 at 04:05:07PM +0200, mauede at alice.it wrote:> Maybe I expect too much from a non compiled language. > Anyway, I wonder whether it is possible in R to set constant values > without using any memory location that would take useless space > bacause such values are not going to be changed along the program.If not in memory, where would the data live? None of the compiled or interpreted languages I have come accross implement magic. cu Philipp -- Dr. Philipp Pagel Lehrstuhl f?r Genomorientierte Bioinformatik Technische Universit?t M?nchen Wissenschaftszentrum Weihenstephan 85350 Freising, Germany http://webclu.bio.wzw.tum.de/~pagel/
Ben Bolker
2009-Aug-13 18:23 UTC
[R] how to get R interpreter to remember constant values without using any memory location
mauede wrote:> > Maybe I expect too much from a non compiled language. > Anyway, I wonder whether it is possible in R to set constant values > without using any memory location that would take useless space > bacause such values are not going to be changed along the program. It's > just a way to assign a mnemnic name tos some constant values. > For instance, I would like R interpreter to replace all occurrences of > mnemonic "Monday" with the number 1, "Tuesday" with the number 2, > "Wednesday with the number 3, and so on ... without having to assign > such values to memory locations. > Maybe environment variables are the way to go ? > >It would help if you were a little bit more specific about what you wanted to do and why. My initial reaction is that this is exactly the thing that the "factor" class in R is designed to do -- maintain a list of unique names corresponding to integer codes, and handle them (almost) transparently. (There are a few tricky aspects to dealing safely/correctly with factor conversions: see http://wiki.r-project.org/rwiki/doku.php?id=tips:data-factors:factors ) Ben Bolker -- View this message in context: http://www.nabble.com/how-to-get-R-interpreter-to-remember-constant-values-without-using-any-memory-location-tp24955624p24956298.html Sent from the R help mailing list archive at Nabble.com.
Ben Bolker
2009-Aug-13 18:24 UTC
[R] how to get R interpreter to remember constant values without using any memory location
mauede wrote:> > Maybe I expect too much from a non compiled language. > Anyway, I wonder whether it is possible in R to set constant values > without using any memory location that would take useless space > bacause such values are not going to be changed along the program. It's > just a way to assign a mnemnic name tos some constant values. > For instance, I would like R interpreter to replace all occurrences of > mnemonic "Monday" with the number 1, "Tuesday" with the number 2, > "Wednesday with the number 3, and so on ... without having to assign > such values to memory locations. > Maybe environment variables are the way to go ? > >It would help if you were a little bit more specific about what you wanted to do and why. My initial reaction is that this is exactly the thing that the "factor" class in R is designed to do -- maintain a list of unique names corresponding to integer codes, and handle them (almost) transparently. (There are a few tricky aspects to dealing safely/correctly with factor conversions: see http://wiki.r-project.org/rwiki/doku.php?id=tips:data-factors:factors ) Ben Bolker -- View this message in context: http://www.nabble.com/how-to-get-R-interpreter-to-remember-constant-values-without-using-any-memory-location-tp24955624p24956310.html Sent from the R help mailing list archive at Nabble.com.
Ben Bolker
2009-Aug-13 18:25 UTC
[R] how to get R interpreter to remember constant values without using any memory location
mauede wrote:> > Maybe I expect too much from a non compiled language. > Anyway, I wonder whether it is possible in R to set constant values > without using any memory location that would take useless space > bacause such values are not going to be changed along the program. It's > just a way to assign a mnemnic name tos some constant values. > For instance, I would like R interpreter to replace all occurrences of > mnemonic "Monday" with the number 1, "Tuesday" with the number 2, > "Wednesday with the number 3, and so on ... without having to assign > such values to memory locations. > Maybe environment variables are the way to go ? > >It would help if you were a little bit more specific about what you wanted to do and why. My initial reaction is that this is exactly the thing that the "factor" class in R is designed to do -- maintain a list of unique names corresponding to integer codes, and handle them (almost) transparently. (There are a few tricky aspects to dealing safely/correctly with factor conversions: see http://wiki.r-project.org/rwiki/doku.php?id=tips:data-factors:factors ) Ben Bolker -- View this message in context: http://www.nabble.com/how-to-get-R-interpreter-to-remember-constant-values-without-using-any-memory-location-tp24955624p24956333.html Sent from the R help mailing list archive at Nabble.com.
Ben Bolker
2009-Aug-13 18:26 UTC
[R] how to get R interpreter to remember constant values without using any memory location
mauede wrote:> > Maybe I expect too much from a non compiled language. > Anyway, I wonder whether it is possible in R to set constant values > without using any memory location that would take useless space > bacause such values are not going to be changed along the program. It's > just a way to assign a mnemnic name tos some constant values. > For instance, I would like R interpreter to replace all occurrences of > mnemonic "Monday" with the number 1, "Tuesday" with the number 2, > "Wednesday with the number 3, and so on ... without having to assign > such values to memory locations. > Maybe environment variables are the way to go ? > >It would help if you were a little bit more specific about what you wanted to do and why. My initial reaction is that this is exactly the thing that the "factor" class in R is designed to do -- maintain a list of unique names corresponding to integer codes, and handle them (almost) transparently. (There are a few tricky aspects to dealing safely/correctly with factor conversions: see http://wiki.r-project.org/rwiki/doku.php?id=tips:data-factors:factors ) Ben Bolker -- View this message in context: http://www.nabble.com/how-to-get-R-interpreter-to-remember-constant-values-without-using-any-memory-location-tp24955624p24956351.html Sent from the R help mailing list archive at Nabble.com.
Don MacQueen
2009-Aug-13 19:17 UTC
[R] how to get R interpreter to remember constant values without using any memory location
Like Ben, I wonder what the reason for doing this is. First of all, the amount of memory indicated by your example is so small I can't imagine it would make any difference. If you have such a large number of values that the amount of memory is significant -- and store them somewhere that isn't in memory (such as physical disk memory), then reading them into memory when you need to use them might affect performance a lot. Environment variables use memory also -- it's just someone else's memory (the OS instead of R). -Don At 4:05 PM +0200 8/13/09, <mauede at alice.it> wrote:>Maybe I expect too much from a non compiled language. >Anyway, I wonder whether it is possible in R to set constant values >without using any memory location that would take useless space >bacause such values are not going to be changed along the program. >It's just a way to assign a mnemnic name tos some constant values. >For instance, I would like R interpreter to replace all occurrences >of mnemonic "Monday" with the number 1, "Tuesday" with the number >2, "Wednesday with the number 3, and so on ... without having to >assign such values to memory locations. >Maybe environment variables are the way to go ? > >Thank you in advance for your advice, >Maura > > > > >tutti i telefonini TIM! > > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at r-project.org mailing list >https://*stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide http://*www.*R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.-- -------------------------------------- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA 925-423-1062