Re: [R] list and <<-

2013-10-22 Thread Greg Snow
Look carefully at your output (and I don't think that you are showing us the output of what you actually ran in the order that you ran it). After running `x %=% 1` you should see that x has the value `1`, but your output shows `2`, this is the result of the next command `y$a %=% 2`, see the `<<-` a

Re: [R] list and <<-

2013-10-22 Thread Taiyun Wei
Many thanks:) I have a list(), eg. named opt, I want to check and assign values to it: if(is.null(opt$a)) opt$a = 'x' if(is.null(opt$b)) opt$a = 'y' ... I need to do a lot of these jobs, so I write a function to simplify it: '%=%' = function(x, y){ if(is.null(x)) { x <<- y } }

Re: [R] list and <<-

2013-10-21 Thread Greg Snow
See fortune(174). It is best to avoid using '<<-', if you tell us what you are trying to accomplish then we may be able to provide a better means to accomplish it. On Sat, Oct 19, 2013 at 10:28 PM, Taiyun Wei wrote: > Dear All, > >> opt = list() >> opt$aa <<- TRUE > Error in opt$aa <<- TRUE : ob

Re: [R] list and <<-

2013-10-19 Thread David Winsemius
On Oct 19, 2013, at 9:28 PM, Taiyun Wei wrote: > Dear All, > >> opt = list() >> opt$aa <<- TRUE > Error in opt$aa <<- TRUE : object 'opt' not found Try _not_ using `<<-` > Why? There wasn't an object by htat name in the enclosing environment. -- David Winsemius Alameda, CA, USA ___

[R] list and <<-

2013-10-19 Thread Taiyun Wei
Dear All, > opt = list() > opt$aa <<- TRUE Error in opt$aa <<- TRUE : object 'opt' not found Why? -- Regards, Taiyun -- Taiyun Wei Homepage: http://blog.cos.name/taiyun/ Phone: +86-15201142716 Renmin University of China __ R-help@r-project.org maili