I propose a simple solution via the clipboard. Function tabout sends the normal output to the console plus a tab-delimited version thereof to the clipboard. Then, you can directly paste e.g. into excel.
tabout <- function(output){
print(output)
capture.output(output, file = "clipboard", append = FALSE,
type = "output", split = FALSE)
lines <- readClipboard()
for(i in 1 : 5) {lines <- gsub(" ", " ", lines, fixed=TRUE)}
lines <- gsub(" ", "\t", lines, fixed=TRUE)
writeClipboard(lines)
}
myanova <- Anova(mymodel, type="III")
tabout(myanova)
While this is mocog = most ordinary code of the galaxy ;^), it does the main job of placing numbers in columns. A slightly more elaborate version below uses a set of phrases that include blanks, but should be kept in one piece in the output (i.e should not be split by inserting tab's).
glmphrases <- c(
"Sum Sq", "F value", "Std. Error", "t value", "test statistic",
"test stat", "approx F", "num Df", "den Df", "p adj",
" = ", " ~ ", " : ", " on ", " and ", "Signif. codes: 0",
"'***' 0.001", "'**' 0.01", "'*' 0.05", "'.' 0.1", "' ' 1"
)
tabout <- function(output, phrases = glmphrases){
# send "output" to the console and a copy to the clipboard
print(output)
capture.output(output, file = "clipboard", append = FALSE,
type = "output", split = FALSE)
lines <- readClipboard()
# collapse repeated blanks and replace with tabs
for(i in 1 : 5) {lines <- gsub(" ", " ", lines, fixed=TRUE)}
lines <- gsub(" ", "\t", lines, fixed=TRUE)
# retain each phrase in one piece and write back to clipboard
phrases.tab <- gsub(" ", "\t", phrases, fixed=TRUE)
for(i in 1 : length(phrases)){
lines <- gsub(phrases.tab[i], phrases[i], lines, fixed=TRUE)
}
writeClipboard(lines)
}
myanova <- Anova(mymodel, type="III")
tabout(myanova)
Hope this is useful, best wishes
Kleks