Rスクリプトからテキストファイルをエクスポートするにはどうすればいいですか?私は結果に関係なく印刷されるテキストをプリセットしたいが、テキストファイルで変更可能な変数も追加したい。私がこれを行う方法を知っている唯一の方法は、sink
とcat
を使用することです。問題は、それぞれの独立した行にcat
を作成する必要があることです。各行にcat
を使用せずに大きな段落を書く方法がありますか?異なる変数の結果を出力するためにRでテキストファイルを作成するには?
x = 1:10
sink("~/Desktop/TEST.txt", type=c("output", "message"), append = FALSE)
"=============================================================== \n
NEW MODEL
===============================================================
Summary of the model:"
x
# model.summary$BUGSoutput$sims.list
sink(NULL)
出力は次のようになります。
[1] "=============================================================== \n\nNEW MODEL \n=============================================================== \nSummary of the model:"
[1] 1 2 3 4 5 6 7 8 9 10
しかし、私はこのような何か持っていることを好むだろう:あなたはこれを書くことができます(ただし、書き込みをしない方法がある
===============================================================
NEW MODEL
===============================================================
Summary of the model:
1 2 3 4 5 6 7 8 9 10
をそれぞれの猫は?):
x = 1:10
sink("~/Desktop/TEST.txt", type=c("output", "message"), append = FALSE)
cat("===============================================================\n")
cat("NEW MODEL\n")
cat("===============================================================\n")
cat("Summary of the model:\n")
x
cat("# model.summary$BUGSoutput$sims.list\n")
sink(NULL)
===============================================================
NEW MODEL
===============================================================
Summary of the model:
[1] 1 2 3 4 5 6 7 8 9 10
# model.summary$BUGSoutput$sims.list
をしかし興味深いことに、これが動作していません:3210これを取得するには
yo <- function(x) {
sink("~/Desktop/potato.txt", type="output")
writeLines("===============================================================
NEW MODEL
===============================================================
Summary of the model:")
x
# other stuff
sink()
}
yo(1:10)
出力:
===============================================================
NEW MODEL
===============================================================
Summary of the model:
をあなたは基本的にプレーンテキスト –