Domain-Specific Languages in R by Thomas Mailund

Domain-Specific Languages in R by Thomas Mailund

Author:Thomas Mailund
Language: eng
Format: epub
Publisher: Apress, Berkeley, CA


## [1] 5

However, this will fail if we refer to the promise that needs the variable before we compute it.

h <- function(x, y = 2 * w) {

res <- x + y

w <- 2

res

}

h(1)

## Error in h(1): object 'w' not found

We have to be careful if a promise depends on a variable that we update during a computation. Note that a promise is evaluated only once; after the evaluation, the variable that used to hold it now holds the result of the evaluation and no longer the promise expression. If we change variables that occurred in the promise, we do not update the value that the variable now holds.

h <- function(x, y = 2 * w) {

w <- 1

res <- x + y

w <- 2

res

}

h(1)



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.