1 / 4

Function and Environments

Function and Environments. What’s going on inside a function. functions. In R, functions are called by value , that is, the value of the argument is copied into the function

jcarrigan
Download Presentation

Function and Environments

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Function and Environments What’s going on inside a function

  2. functions • In R, functions are called by value, that is, the value of the argument is copied into the function • In Fortran and C, functions are called by name, that is, only pointers to the argument variables are passed to the function • R avoids some weird function behavior, but it is wasteful in terms of space

  3. Local and Global • The value of any argument variable is local to the function, as is the result of any assignment to a variable inside the function • If R cannot find a variable locally (it is global), it will look outside the function for the value • The function’s arguments and local variables form an environment, nested within environments global to it, all the way to the top-level Global Environment

  4. Environments Global Environment d f1 → f2 → f1’s environment x (argument) v (local assignment) f2’s environment x (argument) v, d (local assignment)

More Related