R: function's local variable used as (the function's) parameter

codes:
test<-function(x=1,y=lv*3) {
    lv<-1
    x+y
}
test()
4
test(2)
5
test(1,1)
2
now have some change:
test<-function(x=1,y=lv*3) {
    cat(x+y,"\n")
    lv<-1
    x+y
}
test()
Error in cat(x + y, "\n") : object 'lv' not found
So, a function's local variable can be used to initialize the function's (default)parameter once that local variable has been initialized.

posted on 2012-08-23 14:08 ewre 阅读(289) 评论(0)  编辑 收藏 引用 所属分类: R


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


导航

<2012年8月>
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678

留言簿(2)

文章分类

文章档案

最新评论

阅读排行榜