R 스크립트에서 텍스트 파일을 내보내려면 어떻게해야합니까? 결과에 관계없이 인쇄 할 텍스트를 미리 설정하고 싶지만 텍스트 파일에서 변경할 수있는 변수를 추가하고 싶습니다. 이 작업을 수행하는 방법을 알고있는 유일한 방법은 sink
및 cat
을 사용하는 것입니다. 문제는 각 독립 줄마다 cat
을 만들어야한다는 것입니다. 각 줄마다 cat
을 사용하지 않고 큰 단락을 쓸 수있는 방법이 있습니까?다른 변수의 결과를 출력하기 위해 R로 텍스트 파일을 만드는 방법은 무엇입니까?
[1] "=============================================================== \n\nNEW MODEL \n=============================================================== \nSummary of the model:"
[1] 1 2 3 4 5 6 7 8 9 10
하지만 이런 일이하는 것을 선호 :
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)
는 출력은 다음과 같습니다
===============================================================
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: