When/how/where is parent.frame in a default argument interpreted?

后端 未结 1 963
南旧
南旧 2020-12-18 12:11

Truth be told, I\'m just being lazy here, but perhaps someone could someday profit from the answer being here.

Say I define a function like:

fn<-f         


        
相关标签:
1条回答
  • 2020-12-18 13:00

    Default arguments are evaluated within the evaluation frame of the function call, from which place parent.frame() is the calling environment. envir's value will thus be a pointer to the environment from which fn was called.

    Also, just try it out to see for yourself:

    debug(fn)
    fn()
    # debugging in: fn()
    # debug at #2: {
    # }
    Browse[2]> envir
    # <environment: R_GlobalEnv>
    
    0 讨论(0)
提交回复
热议问题