Having the following
> library(gbm)
> mdl<-gbm::gbm(data=iris,formula=Species ~ .,distribution="gaussian")
Then:
> mdl
gbm::gbm(formula = Species ~ ., distribution = "gaussian", data = iris)
A gradient boosted model with gaussian loss function.
100 iterations were performed.
There were 4 predictors of which 4 had non-zero influence.
What is what I want.
However, If I use do.call:
> mdl<-do.call(gbm::gbm,list(data=iris,formula=Species ~ .,distribution="gaussian"))
Then
> mdl
(function (formula = formula(data), distribution = "bernoulli",
data = list(), weights, var.monotone = NULL, n.trees = 100,
interaction.depth = 1, n.minobsinnode = 10, shrinkage = 0.1,
bag.fraction = 0.5, train.fraction = 1, cv.folds = 0, keep.data = TRUE,
...
...
...
A gradient boosted model with gaussian loss function.
100 iterations were performed.
There were 4 predictors of which 4 had non-zero influence.
It prints the definition of gbm function at the beginning, then the gbm call (including the whole dataset iris) and finally the text that I am looking for.
I need to use do.call because I want to parametrize all the arguments for any classification algorithm and then put the output inside a verbatimTextOutput in shiny.
Is there any way to prevent do.call to return the definition of gbm as well as the entire dataset?. Or maybe other way to execute gbm passing arguments inside a list?
Thanks.
We have to do two things to prevent this behavior:
First, we can use
substitute()oniris. This will prevent thecallfrom listing all columns of theirisdata set.Second, we should avoid using
gbm::gbmindo.calland rather load the library and use the string"gbm"instead to call the function:If we use
gbm::gbminside do call it will include the whole function definition in the captured call:Created on 2023-02-20 by the reprex package (v2.0.1)