Reputation: 833
I'm trying to use stargazer
to format output from the lmList
function in the nlme
package. I can get stargazer
to work if I manually index each list element, but not if I just pass stargazer
the full list. Any suggestions for how I can get stargazer
to recognize the lmList
output?
library(nlme)
library(stargazer)
data("iris")
m <- lmList(Sepal.Length ~ Sepal.Width | Species, data = iris)
stargazer(m, type = "text") # "% Error: Unrecognized object type.
stargazer(m[[1]], m[[2]], m[[3]], type = "text")
Upvotes: 1
Views: 298
Reputation: 21
You need to package all arguments to stargazer as a list and then get stargazer to accept a list of arguments. The magic function to do this is do.call
.
do.call
's first argument is the function and the second argument is the list of arguments to pass to that function in the first argument.
So something like this should work:
do.call(stargazer, c(m, type = "text"))
Also FYI the tidyverse version of do.call
is invoke
so this is the same.
invoke(stargazer, c(m, type = "text"))
Invoke will be nicer because you can pass additional arguments (like type above) without putting them in the list.
Upvotes: 2