Questions tagged [non-standard-evaluation]

156 questions
0
votes
0 answers

Conditionally quote/substitute an expression if not already quoted

I'm looking for a way to quote an argument passed to function (consider substitute(), ggplot2's aes(), subset() or data.table's [ behavior), but do it conditionally - only if not already quoted with quote(). This is because I'd like to easily chain…
mjktfw
  • 840
  • 6
  • 14
0
votes
2 answers

R function to install missing packages

For one of my scripts I want to write an R function that checks if a package is already installed: if so it should use library() to import it in the namespace, otherwise it should install it and import it. I assumed that pkgname is a string and…
lucacerone
  • 9,859
  • 13
  • 52
  • 80
-1
votes
1 answer

How to remove the enclosing brackets when bquote contains multiple expressions?

bquote({ A <- 4 print(A) }) output: { A <- 4 print(A) } What can I do so that the output is simply: A <- 4 print(A)
-1
votes
1 answer

Nested functions in parse(eval(...), envir = custom)

I have a custom R environment e = new.env() e[["a"]] = function(x) b(x) e[["b"]] = function(x) x + 1 Function b() runs as expected. > eval(parse(text = "b(1)"), envir = e) [1] 2 But a(1) throws an error. > eval(parse(text = "a(1)"), envir =…
landau
  • 5,636
  • 1
  • 22
  • 50
-2
votes
3 answers

How to modify attributes of a variable within data frame inside an R function

The base::levels help file https://stat.ethz.ch/R-manual/R-devel/library/base/html/levels.html contains the following example of modifying the levels of a variable: z <- gl(3, 2, 12, labels = c("apple", "salad", "orange")) z levels(z) <- c("fruit",…
StasK
  • 1,525
  • 10
  • 21
-4
votes
1 answer

How to use dynamic column inside of bquote

a <- "t" bquote(data.frame(.(a) = 1:10) Error: unexpected '=' in "bquote(data.frame(.(a) =" a needs to be dynamic. How can this be accomplished?
1 2 3
10
11