l******9 发帖数: 579 | 1 【 以下文字转载自 Statistics 讨论区 】
发信人: light009 (light009), 信区: Statistics
标 题: pass arguments by reference in R
发信站: BBS 未名空间站 (Fri Apr 11 14:19:03 2014, 美东)
I need to do pass by reference in R by R studio on win 7.
My code:
myfunc<-function(myhash.arg, b)
{
myhash <- myhash.arg
if (!has.key("first", myhash))
myhash["first"] <- list()
alist <- myhash["first"]
alist <- append(alist, i)
eval.parent(substitute(myhash.arg<-myhash))
return(0)
}
ahash<-hash()
for(i in 1:5)
{
myfunc(myhash.arg = ahash, b = i)
print(c("length of ahash is ", length(ahash)))
print(c("length of ahash list is ", length(ahash["first"])))
}
but, the list size is always 1, the appended elements are missed.
Any help would be appreciated. | m****r 发帖数: 120 | 2 能不能就用个全局变量好了。或者试试assign?总之要找到正确的环境下的变量
【在 l******9 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 【 以下文字转载自 Statistics 讨论区 】 : 发信人: light009 (light009), 信区: Statistics : 标 题: pass arguments by reference in R : 发信站: BBS 未名空间站 (Fri Apr 11 14:19:03 2014, 美东) : I need to do pass by reference in R by R studio on win 7. : My code: : myfunc<-function(myhash.arg, b) : { : myhash <- myhash.arg : if (!has.key("first", myhash))
|
|