I've wondered about this myself and went source code sleuthing.
The reason there is no '[1]' is that summary(model)
returns an object of class summaryDefault
which has a method SummaryDefault.print
defined for it which gets called by the repl when it prints the summary info to the terminal and returns the summaryDefault object invisibly. So, the underlying vector of summary stats itself is not printed by print.default
, which provides those indexes inside brackets.
However, the lack of the '[1]' is not the reason org is returning a blank result.
Here is the reason:
When you declare an org-mode code block with :returns value
, Org mode tries to convert the value of the last expression in your code block into something that can be formatted as an org table (i.e. with |
characters as delimiters).
It takes advantage of R's special variable .Last.value
to get the value that needs to be converted.
It tries to convert this value to by calling the R function write.table
on it, writing to a temp file which it then reads/parses/reformats into well formatted org table.
Alas, write.table
, when called on an object of class SummaryDefault
, generates an error, which gets caught and is silently un-reported, but that temp file winds up empty.
So there is nothing to reformat into an org table.
Your options today include:
- OK: declare your code block instead with
:returns output
. Downside of this is that it will return ALL output, and the summary is not nicely reformatted into an org-table which maybe you want. - OK: leave it as
returns :value
, but make the last expression in your block becapture.output(summary(model))
. The output will be a one column table, with one row for each line of output. - Better: leave it as
returns :value
, but make the last expression beunclass(summary(model))
. Then the vector will get printed. Add a:rownames yes
and we're looking pretty. - Betterer: leave it as
returns :value
, but uset(summary(model))
to simultaneously unclass the value and get it formatted wide. - Betterest: leave it as
returns :value
, but uset(t(summary(model)))
to simultaneously unclass the value and keep it formatted skinny.
It is after all a reach to expect org to magically be able to convert any R data structure to a data.frame like thing and from there to an org table. I suppose org magic could catch the error and try something else, like calling t(t(.))
on the object it is trying to coerce to something tabular. Or as(.,data.frame)
. I'm not sure that's in the org "spirit". I wonder...
In any case, it would be good if org mode would raise an error, like, "Erhm, how do expect me to convert a summaryDefault object to a table".
Or?