0

I am trying to customize my ggpairs function and I for that I am using a data.frame that I have imported from keggle. Here is a minumum reproducible example:

BMI = c(1,2,3,4,5,6,7,8)
Glucose = c(0.4, 0.3, 0.6, 0.4, 0.7, 1, 0.9, 0.5) 
example_df = data.frame(BMI, Glucose)
bla = function(data, mapping){
  x <- eval(mapping$x, data)
  y <- eval(mapping$y, data)
  return(cor.test(x,y))
}

bla(diabetes, aes(BMI, Glucose))

When I print x and y without the return(cor.test(x,y)) I get the names of the columns I am working with. When I want to run the cor.test I get the following error:

Error in stats::model.frame(formula = x, data = y) : object 'x' not found

Here is the traceback:

6.
stats::model.frame(formula = x, data = y)
5.
eval(m, environment(formula))
4.
eval(m, environment(formula))
3.
cor.test.formula(x, y)
2.
cor.test(x, y)
1.
bla(diabetes, aes(BMI, Glucose))
Pablo Rodriguez
  • 233
  • 1
  • 10

0 Answers0