Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dissuade from doing assignments inside a call to a function #1628

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Functions.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,8 @@ A promise has three components:
y
```

Note that doing the above is generally considered bad style since – due to the nature of lazy evaluation – there is no guarantee that the argument will ever be evaluated and hence the assignment may never take place.[^off-doc-argeval]

* A value, which is computed and cached the first time a promise is
accessed when the expression is evaluated in the specified environment.
This ensures that the promise is evaluated at most once, and is why you
Expand All @@ -587,6 +589,7 @@ A promise has three components:

You cannot manipulate promises with R code. Promises are like a quantum state: any attempt to inspect them with R code will force an immediate evaluation, making the promise disappear. Later, in Section \@ref(quosures), you'll learn about quosures, which convert promises into an R object where you can easily inspect the expression and the environment.

[^off-doc-argeval]: See [chapter 4.3.3 _Argument evaluation_](https://cran.r-project.org/doc/manuals/r-release/R-lang.html#Argument-evaluation) of the official R language definition for some more information about the topic.

### Default arguments
\index{functions!default values}
Expand Down