回复 第1楼 的 fan:
两个想法。
1.直接读取所有,然后提取最后一行。
<br />
con <- file("test.md")<br />
open(con)<br />
out <- scan(con,what="char(0)",sep="\n")<br />
out[length(out)]<br />
close(con)<br />
</p>
2.走循环的套路,每次读取1行,直到读取到文尾。
<br />
con <- file("test.md")<br />
open(con)<br />
out <- scan(con,1,what="char(0)",sep="\n",quiet=TRUE)<br />
tmp <- scan(con,1,what="char(0)",sep="\n",quiet=TRUE)<br />
while(length(tmp)!=0){<br />
out <- tmp<br />
tmp <- scan(con,1,what="char(0)",sep="\n",quiet=TRUE)<br />
}<br />
close(con)<br />
out<br />
</p>