我尝试将文本附加到多个进程的文件中,但它似乎没有正常工作。
测试脚本:
logfile <- "testing.txt"
for(i in 1:10) {
fileConn<-file(description=logfile, open="a", blocking=T)
writeLines("abcdef", fileConn)
close(fileConn)
}
然后跑步:
Rscript test.r &
Rscript test.r &
Rscript test.r &
Rscript test.r &
Rscript test.r &
Rscript test.r &
Rscript test.r &
Rscript test.r &
Rscript test.r &
Rscript test.r &
只生产35行&#34; abcdef&#34; (预计100)。
测试脚本2:
logfile <- "testing.txt"
for(i in 1:10) {
cat("abcdef", file=logfile, append=TRUE, sep = "\n")
}
制作:
bcdef
abcdef
abcdefabcdef
abcdefabcdef
abcdefabcdef
abcdefabcdefabcdefabcdef
abcdefabcdeff
bcdefabcdef
abcdef
bcdefabcdefabcdef
abcdefabcdefabcdefabcdef
abcdef
等。如何从10个不同的过程获得所需的行为,100行abcdef?
答案 0 :(得分:-1)
Maybe I am missing something but as I understand the question you want a text file with 100 lines each one with abcdef
. It can be achieved with just a:
tex <- as.matrix(rep("abcdef", 100))
write(tex, file = "textfile.txt")