Reputation: 705
Given a linear model:
fit <- lm(mpg~., mtcars)
I tried `r formula(fit)` to print the model/formula inline, but trying to knit the RMarkdown file to PDF or HTML gives errors (error in vapply...)
If it do the same thing inside a triple quoted code chunk, it works fine:
```{r}
formula(fit)
```
formula(fit)
prints the formula on the R interpreter as I would like.
Is there a limitation to what can be done in an inline code chunk, or am I missing something?
Upvotes: 3
Views: 2131
Reputation: 13169
I don't know why exactly, but I think the issue lies in the structure and formatting of a formula-object. I'm guessing that the objects get converted to character in order to be printed. This is why it works (albeit in a weird sequence) for one independent variable, but doesn't work for multiple independent variables.
A workaround is to use
`r format(formula(fit))`
As inline code, it gave me the desired result.
Upvotes: 5