r 语言ylim = c(0 1),r – 懒惰评估:为什么我不能使用plot(…,xlim = c(0,1),ylim = xlim)?...

Quoting from the good manual:

4.3.3 Argument evaluation

One of the most important things to know about the evaluation of

arguments to a function is that supplied arguments and default

arguments are treated differently. The supplied arguments to a

function are evaluated in the evaluation frame of the calling

function. The default arguments to a function are evaluated in the

evaluation frame of the function.

要看看这在实践中意味着什么,创建一个函数,其中一个参数的默认值是另一个参数的值的函数:

f

y

}

当用y的默认值调用时,R看起来在函数调用的评估框架中评估y,即在整个函数的整体被评估的同一个环境中 – 一个x已经好得多的地方确实存在:

f()

# [1] 16

当用提供的值y调用时,R在调用函数的评估框(在这里是全局环境)中查找,找不到x,并让它在其错误信息中知道:

f(y=x^2)

# Error in f(y = x^2) : object 'x' not found

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值