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
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
}
}
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
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
___
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
5 matches
Mail list logo