Re: [R] function that uses a variable name as the parameter

2008-11-13 Thread William Dunlap
On 12/11/2008 7:59 AM, David Croll wrote: > > Hello dear R people! > > > Several times it occurred to me that a function that uses a variable name as a parameter would be helpful, but I did not find out how to write such a function. I have experience in several programming language, but I did no

Re: [R] function that uses a variable name as the parameter

2008-11-12 Thread Greg Snow
David, Having a function that changes global variables is very frowned on with few exceptions. It falls into the category of things that you should never do unless you fully understand why you should never do them (also see fortune(36)). However, what you want to do may be more of a macro than

Re: [R] function that uses a variable name as the parameter

2008-11-12 Thread Duncan Murdoch
On 12/11/2008 7:59 AM, David Croll wrote: Hello dear R people! Several times it occurred to me that a function that uses a variable name as a parameter would be helpful, but I did not find out how to write such a function. I have experience in several programming language, but I did not come

Re: [R] function that uses a variable name as the parameter

2008-11-12 Thread Wacek Kusnierczyk
David Croll wrote: > Hello dear R people! > > > Several times it occurred to me that a function that uses a variable name as > a parameter would be helpful, but I did not find out how to write such a > function. I have experience in several programming language, but I did not > come across a hel

Re: [R] function that uses a variable name as the parameter

2008-11-12 Thread bartjoosen
You're almost there: a <- 12 # starting value add <- function(variable,increment) { variable + increment } add(a,25) you shouldn't assign variable + increment to variable, unless you put a return in your function: add <- function(variable,increment) { variable <- variable + incremen