我結束了寫作一些hacky R代碼(注意它只適用於w/sed,wc和awk可用的系統),它更靈活,並且可以很好地運行memisc的「mtable」函數,這是我生成LaTeX表的首選方式。基本上你把你的表寫到一個文本文件中,然後用(1)你想插入的文件中的行號(2)和你想插入的行以及(3)文件名你想插入(注意這個函數會覆蓋你現有的文件)。該代碼是:
insert.note <-function(linenumber, line, file){
num.lines <- as.numeric(system(paste("wc", file, "| awk '{print $1}'"), intern=TRUE))
tmp <- tempfile()
system(paste("head -n ", linenumber, file, "> ", tmp))
sink(tmp, append=TRUE)
cat(line)
sink()
system(paste("tail -n", num.lines - linenumber, file, ">>", tmp))
system(paste("mv", tmp, file))
}
作爲一個輔助功能,該代碼使用mtable的雙&列間距創建乳膠有效行:
create.note <- function(l, include.row.end = TRUE){
n <- length(l)
s <- ""
i <- 1
for(note in l){
if(i < n){
cap <- "&&"
} else {
if(include.row.end){
cap <- "\\\\ \n "
} else {
cap <- " \n"
}
}
s <- paste(s, note, cap)
i <- i + 1
}
s
}
的include.row.end參數是你想要的情況下通過它像「\ midrule」,並不想獲得額外的線。