我正在一个函数中构建模型,类似于:
some_form <- formula("Species == 'virginica' ~ Petal.Width")
some_fam <- "binomial"
some_fit <- glm(formula = some_form, family = some_fam, data = iris )
当我在结果上调用summary
时,函数调用包含变量名。
summary(some_fit) # could also just use some_fit$call
# Returns
# Call:
# glm(formula = some_form, family = some_fam, data = iris)
但我希望让它返回原始(评估)的公式和姓氏。我想要的输出如下:
# To produce desired output
summary(glm(Species=='virginica' ~ Petal.Width, family = binomial, data = iris))
# Call:
# glm(formula = Species == "virginica" ~ Petal.Width, family = binomial, data = iris)
# ^ This is what I want!
我尝试过:
some_fit <- glm(eval(some_form), family = eval(some_fam), data = iris )
summary(some_fit)
# Returns
# Call:
# glm(formula = eval(some_form), family = eval(some_fam), data = iris)
用eval()
或eval(quote())
替换eval(substitute())
我得到了类似的结果 - $call
只是复制我传入其中的任何表达式。
这可能是一个基本问题(并且无论如何,如果它是重复的,请标记 - 我可能没有使用正确的搜索条件),但我真诚地感谢: