%20%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%97%E3%81%9F%20Rmarkdown%20%E3%83%81%E3%83%A3%E3%83%B3%E3%82%AF%E3%81%8C%20LaTeX%20%E3%83%86%E3%83%BC%E3%83%96%E3%83%AB%E3%81%AE%E3%83%AC%E3%83%B3%E3%83%80%E3%83%AA%E3%83%B3%E3%82%B0%E3%82%92%E5%81%9C%E6%AD%A2%E3%81%97%E3%81%BE%E3%81%97%E3%81%9F.png)
論文の .pdf 結果セクションを編むために使用するデータ分析 Rmarkdown ファイルがあります。今朝、Rstudio でニット ボタンを使用して PDF を編んだとき、美しく機能する LaTeX テーブル コードがありました。しかし、どうやら壊れてしまったようです。常に次のエラーと出力が表示されます: error in as.string(y) : Cannot coerce argument to a string
、Calls: <Anonymous> ... print -> print.xtable -> +.string -> paste -> as.string
データフレームclass(df)
を読み取り、例を[1] "data.table" "data.frame"
呼び出した後にエラーが発生します。sum_table
私が試したこと:
- xtable() および print() 関数への追加を 1 つずつ削除して、非常にシンプルな形式に戻します。
- Rmd チャンクとしてではなく、行ごとにコードを実行します。
- xtable() に表示引数を追加するxtable ドキュメント
- xtable と R をアンインストールして再インストールしました。MacOS 10.12.6 (古いコンピュータ)、R 3.6.3、Rstudio 1.2.5033 を実行しています。
booktabs=TRUE
print() に引数を追加しましたxtable の例
このエラーまたはトラブルシューティングについて何かアイデアはありますか?
シンプルな Rmd チャンクの例:
---
output:
pdf_document:
fig_caption: yes
indent: true
---
# Rmd chunk settings
# results = 'asis' to output LaTex code that is recognized as code
{R Summary_Table, echo = FALSE, results = 'asis'}
library(knitr)
library(tinytex)
library(xtable)
options(xtable.timestamp = FALSE)
df <- data.frame(A = c(1:10),
B = c(11:20),
C = c(21:30))
sum_table <- xtable(df)
sum_table # Error thrown here "as.string(y) : Cannot coerce argument to a string"
print.xtable(sum_table)
# try another print function
print(sum_table)
# try adding booktabs argument
print(sum_table, booktabs = TRUE)
#Tried adding display argument to xtable(), extra for xtable's automatic
# number column. Thought maybe num variables couldn't be turned into a string?
sum_table2 <- xtable(df, display = c("s","f","f","f"))
sum_table2