Menu Close

Is it possible to use non standard evaluation in R?

Is it possible to use non standard evaluation in R?

In most programming languages, you can only access the values of a function’s arguments. In R, you can also access the code used to compute them. This makes it possible to evaluate code in non-standard ways: to use what is known as non-standard evaluation, or NSE for short.

What does it mean to use non standard evaluation?

This makes it possible to evaluate code in non-standard ways: to use what is known as non-standard evaluation, or NSE for short. NSE is particularly useful for functions when doing interactive data analysis because it can dramatically reduce the amount of typing.

How is capturing expressions used in non standard evaluation?

Capturing expressions teaches you how to capture unevaluated expressions using substitute (). Non-standard evaluation shows you how subset () works by combining substitute () with eval () to allow you to succinctly select rows from a data frame. Scoping issues discusses scoping issues specific to NSE, and will show you how to resolve them.

Which is an example of dynamic scope in R?

In R terminology this is called the parent frame and is accessed with parent.frame(). This is an example of dynamic scope : the values come from the location where the function was called, not where it was defined.

Can you use non-standard evaluation in R?

Non-Standard Evaluation is a pretty controversial topic in R circles, and even in the R documentation. Whether you like it never, sometimes, or always, is neither here nor there. What matters is that R allows it. Not many languages give the programmer the power to implement, use, and abuse Non-Standard Evaluation (“NSE”), or anything like it.

This makes it possible to evaluate code in non-standard ways: to use what is known as non-standard evaluation, or NSE for short. NSE is particularly useful for functions when doing interactive data analysis because it can dramatically reduce the amount of typing.

Capturing expressions teaches you how to capture unevaluated expressions using substitute (). Non-standard evaluation shows you how subset () works by combining substitute () with eval () to allow you to succinctly select rows from a data frame. Scoping issues discusses scoping issues specific to NSE, and will show you how to resolve them.

How are substitute and deparse used in base R?

substitute() is often paired with deparse(). That function takes the result of substitute(), an expression, and turns it into a character vector. g <- function(x) deparse(substitute(x)) g(1:10) #> [1] “1:10” g(x) #> [1] “x” g(x + y^2) #> [1] “x + y^2”. There are a lot of functions in Base R that use these ideas.

In most programming languages, you can only access the values of a function’s arguments. In R, you can also access the code used to compute them. This makes it possible to evaluate code in non-standard ways: to use what is known as non-standard evaluation, or NSE for short.

What happens when subset performs a non-standard evaluation?

In other words, subset performs non-standard evaluation on the expression hp > 250. Compare to what happens with an expression that is evaluated in the standard way: We get an error because hp is not defined in my workspace.

Where does the subset argument in rdocumentation work?

For data frames, the subset argument works on the rows. Note that subset will be evaluated in the data frame, so columns can be referred to (by name) as variables in the expression (see the examples). The select argument exists only for the methods for data frames and matrices.

How do you evaluate an expression in R?

In this R tutorial, I’ll explain how to evaluate an expression with the eval function. Let’s first have a look at the basic R syntax and the definition of eval: The eval function evaluates (i.e. calculates) an R expression and returns the result.

Which is an example of an eval function in R?

The eval function evaluates (i.e. calculates) an R expression and returns the result. Example 1: Basic application of the eval() Function in R. The eval R function is usually applied to an expression.