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 } } x=NULL y=list() > is.null(x) [1] TRUE > is.null(y$a) [1] TRUE > x %=% 1; > x [1] 2 > y$a %=% 2; ## Can't assign 2 to y$a, still NULL > y$a NULL On Mon, Oct 21, 2013 at 11:38 PM, Greg Snow <538...@gmail.com> wrote: > 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 <weitai...@gmail.com> wrote: > > Dear All, > > > >> opt = list() > >> opt$aa <<- TRUE > > Error in opt$aa <<- TRUE : object 'opt' not found > > > > Why? > > > > -- > > Regards, > > Taiyun > > -- > > Taiyun Wei <weitai...@gmail.com> > > Homepage: http://blog.cos.name/taiyun/ > > Phone: +86-15201142716 > > Renmin University of China > > > > ______________________________________________ > > R-help@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. > > > > -- > Gregory (Greg) L. Snow Ph.D. > 538...@gmail.com > -- Regards, Taiyun -- Taiyun Wei <weitai...@gmail.com> Homepage: http://blog.cos.name/taiyun/ Phone: +86-15201142716 Renmin University of China [[alternative HTML version deleted]] ______________________________________________ R-help@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.