I believe this is expected from how sjPlot is working.
-
When you click the Knit button, code will be exectute in the knit context. This means than a special printing method will be used. knitr::knit_print. sjPlot defines a special method sjPlot:::knit_print.sjTable() to print its table. If you look at the source, this function won't write to file, but will output directly in the file as usual during knitting.
-
When you run outside of knit, then print() will be used. And this is sjPlot:::print.sjTable() that will write to file if you look at the source code.
So I believe this is current expected behavior. You can open a feature request in sjPlot to do both in case somehow when knitting.
If you really want only the writting to file and not table included in the knitted output, then you could just hack and print the value to file explicitly.
```{r tabmodel}
library(sjPlot)
fit <- lm(mpg ~ cyl, data=mtcars)
# if file is defined, sjPlot:::print.sjTable will write to file, always.
print(tab_model(fit, file = "tabmodelOut.html"))
```