I created a function to return a ggplot object like below
uni_var<-function(df,col){
return(ggplot(df,aes(col))+geom_bar())
}
When I called on the mtcars data frame
uni_var(mtcars,cyl)
I get the below error
Error in FUN(X[[i]], ...) : object 'cyl' not found
In addition: Warning message:
In FUN(X[[i]], ...) : restarting interrupted promise evaluation
What is wrong with the my function ?