out_con <- file("out.txt", "w")
write(sprintf("This is line %d.\n",1),out_con,append=T)
write("This is line 2.",out_con,append=T)
close(out_con)
或者
printer = file("out.txt","w")
writeLines("This is line.",con=printer,sep=" ")
writeLines("The same line.",con=printer)
close(printer)
参考:
http://grokbase.com/t/r/r-help/137hry3mga/r-writing-multiple-lines-to-a-file
也可以用sink
sink("tmp_out.txt")
con <- file("raw.txt", "r")
line <- readLines(con, n=1)
while(length(line) != 0) {
c = unlist(strsplit(line, "\t"))
if (c[1] == "Contig") {
#k_test <- rbind(k_test, c)
cat(line)
cat("\n")
}
else if (as.numeric(c[1]) %in% g.out$name) {
##a <- sapply(c, as.numeric)
##k_test <- rbind(k_test, a)
cat(line)
cat("\n")
}
line = readLines(con, n=1)
}
close(con)
sink()
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
网络异常,请检查网络