+1 vote
I've just started to learn R and have read about something called lazy evaluation. I dont understand what that means as it does not exist in any other language. Can somebody explain?
Oct 31, 2018 892 views

## 1 answer to this question.

Let me explain this with an example. Consider the following code, here there are two paramaters passed, a and b. But only a is being used in the function.

```F <- function(a,b)
{
a^2
}```

So when we call the function with just one parameter it assumes that one parameter is the value for the variable that is being used. So if we call the function like this,

F(2)

it assumes 2 to be a's value. Calling the function F with just one parameter doesn’t give any error.

• 52,350 points

While your example is correct about b not being evaluated, your reason is not totally right: F uses 2 for the value of a not because it is used in the function, but because a is the first parameter of F. If F were defined as

```F <- function(a,b)
{
b^2
}```

then calling F(2) would give an error, because a would be given the value of 2, and b has no value.

Lazy evaluation is implemented in a lot of functional languages, like Scala, Haskell, R, and can be used in eager languages like Python (think range function) or even C++. See https://en.wikipedia.org/wiki/Lazy_evaluation for more examples.

## What does the inf special character mean in R?

inf stands for infinity and only applies ...READ MORE

## What does 'r' mean before a Regex pattern?

Since the string is to be treated ...READ MORE

## How do I find out what directory R has chosen to store packages?

.libPaths() // You can use this command ...READ MORE

+1 vote

The error means that R could not ...READ MORE

## By using dpylr package sum of multiple columns

Basically here we are making an equation ...READ MORE

## How to convert a text mining termDocumentMatrix into excel or csv in R?

By assuming that all the values are ...READ MORE

## In a dpylr pipline how to use sample and seq?

For avoiding rowwise(), I prefer to use ...READ MORE

## How to create a list of Data frames?

Basically all we have to do is ...READ MORE

+1 vote