Re: [R] list assignment syntax?

2012-04-03 Thread ivo welch
I finally got around to posting my list of R gripes on a blog at http://ivo-welch.blogspot.com/2012/04/r-annoyances-and-gripes.html . I did put in some time, but I do not expect anyone to read it. it was more for myself. still, if you are curious, I would love to hear where I got it wrong and

Re: [R] list assignment syntax?

2012-04-03 Thread Bert Gunter
Ivo: The primary source of your problems appears to be: Unfortunately, for a generic programming language, R still lacks some sugar. R is **not** a generic programming language, nor was it ever meant to be one. Have you read Chambers's et al books? R was designed as a language for data analysis

Re: [R] list assignment syntax?

2012-03-31 Thread jim holtman
All of this is syntactic sugar. Just because a language does not have the sintax that you are used (e.g, Perl) does not make it bad/hard to use. What is the problem if I have to type a couple of extra lines: f - function(x) list(a = seq_along(x), b=x*3) result - f(1) r1 - result$a r2 - result$b

Re: [R] list assignment syntax?

2012-03-31 Thread ivo welch
what is the problem you are trying to solve? elegance, ease, and readability in my programs. R has morphed from a data manipulation, graphics, and stats program into my mainstay programming language. most of this has been a huge gain. the addition of the parallel package was another recent big

[R] list assignment syntax?

2012-03-30 Thread ivo welch
Dear R wizards: is there a clean way to assign to elements in a list? what I would like to do, in pseudo R+perl notation is f - function(a,b) list(a+b,a-b) (c,d) - f(1,2) and have c be assigned 1+2 and d be assigned 1-2. right now, I use the clunky x - f(1,2) c - x[[1]] d - x[[2]]

Re: [R] list assignment syntax?

2012-03-30 Thread Weidong Gu
You don't need temporary variable x c-f(1,2)[[1]] d-f(1,2)[[2]] Weidong Gu On Fri, Mar 30, 2012 at 6:40 PM, ivo welch ivo...@gmail.com wrote: Dear R wizards:  is there a clean way to assign to elements in a list?  what I would like to do, in pseudo R+perl notation is  f - function(a,b)

Re: [R] list assignment syntax?

2012-03-30 Thread Peter Ehlers
On 2012-03-30 15:40, ivo welch wrote: Dear R wizards: is there a clean way to assign to elements in a list? what I would like to do, in pseudo R+perl notation is f- function(a,b) list(a+b,a-b) (c,d)- f(1,2) and have c be assigned 1+2 and d be assigned 1-2. right now, I use the clunky

Re: [R] list assignment syntax?

2012-03-30 Thread Gabor Grothendieck
On Fri, Mar 30, 2012 at 6:40 PM, ivo welch ivo...@gmail.com wrote: Dear R wizards:  is there a clean way to assign to elements in a list?  what I would like to do, in pseudo R+perl notation is  f - function(a,b) list(a+b,a-b)  (c,d) - f(1,2) and have c be assigned 1+2 and d be assigned 1-2.

Re: [R] list assignment syntax?

2012-03-30 Thread Justin Haynes
You can also take a look at http://stackoverflow.com/questions/7519790/assign-multiple-new-variables-in-a-single-line-in-r which has some additional solutions. On Fri, Mar 30, 2012 at 4:49 PM, Peter Ehlers ehl...@ucalgary.ca wrote: On 2012-03-30 15:40, ivo welch wrote: Dear R wizards:  is

Re: [R] list assignment syntax?

2012-03-30 Thread ivo welch
thanks, everyone. I should have been clearer (as always). I used the numbers as an example only. I am aware that I can put numbers into vectors and get nice R syntax. my problem is that I usually want to return multiple and/or mixed objects, such as multiple data frames. I should have given

Re: [R] list assignment syntax?

2012-03-30 Thread Joshua Wiley
An idiom like this would also work. f - function(a,b) list( data.frame(a+rnorm(20), b), loess( a ~ b) ) lapply(seq_along(out - f(1:20, 1:20)), function(i) assign(c(c, d)[i], out[[i]], envir = .GlobalEnv)) It is not elegant if you are doing this regularly, but, I think, functions typically

Re: [R] list assignment syntax?

2012-03-30 Thread Bert Gunter
,,,But assigning to the global environment is a bad idea. You're just asking for trouble -- overwriting without warning something that's already there. May I suggest a rule of thumb: When things are difficult or clumsy to do in R, don't do them. Of course this is not inviolable, but the OP's

Re: [R] list assignment syntax?

2012-03-30 Thread Jeff Newmiller
I agree that global side effects are a bad idea, but ivo started this by pointing out that it is straightforward to do this in Perl. It might be worth considering adding this capability to R. --- Jeff Newmiller