I have a function foo that takes a data frame as input and returns a ggplot object as output. I need to use the name of the data frame as the title of the plot. I am unable to figure out how to do this.
If I did not pass it to a function, I know that I could use deparse(substitute(df))
to get the desired title. But I am unable to 开发者_开发技巧do it inside the function.
Any thoughts on how to do this?
You have not given a minimal example to show the problem. The following works for me:
a <- expand.grid(x=1:3, y=1:2)
f <- function(df){qplot(x, y, data=a, main=deparse(substitute(df)))}
f(a)
Were you doing something else?
精彩评论