I want to include data argument within custom R function. Right now I am using the following function
Ploy <- function(Sepal.Length = Sepal.Length, Sepal.Width = Sepal.Width,
Petal.Width = Petal.Width){
#Calculate some derived parameters
deltak <- (Sepal.Length - Sepal.Width)/390
ARk <- Petal.Width*2
dat <- cbind.data.frame(deltak, ARk)
#Fitting quadratic model
mod <- lm(deltak ~ poly(ARk, 2, raw = TRUE))
deltaK0 <- abs(mod$coefficients[[1]])
return(c(`DeltaK0` = deltaK0))
}
When I am calling the function I have to use iris$ like
Ploy(Sepal.Length = iris$Sepal.Length, Sepal.Width = iris$Sepal.Width,
Petal.Width = iris$Petal.Width)
I know there is a workaround using with like
with(iris, Ploy(Sepal.Length = Sepal.Length, Sepal.Width = Sepal.Width,
Petal.Width = Petal.Width))
But I want to have the call for the Ploy function like
Ploy(Sepal.Length = Sepal.Length, Sepal.Width = Sepal.Width,
Petal.Width = Petal.Width, data = iris)
How can I achieve it?