I want to write a function f that given:
x <- 1
f(.(y==x))
It returns the string:
"y == 1"
The function should be general enough, that the expression can be arbitrary. For instance, f(.(y==x & z==x))
should return "y == 1 & z == 1"
.
Any ideas?
The function:
g <- function(e) as.character(unlist(e))
does not work for me, as it returns "y == x". I want the replacement to take place.
UPDATE:
Also, this question is not a duplicate of How do I substitute symbols in a language object? I want to create a function f, that means that somehow I need to get the value of x from the caller s environment. My current attempt is this:
require(plyr)
x <- 1
f <- function(e) do.call(substitute, list(e[[1]], parent.frame(1)))
f(.(y==x & z==x))
But it still does not work. Maybe I should use something else instead of parent.frame
?
Many thanks.