cat将CR附加到R中的输出

时间:2019-05-17 19:31:45

标签: r

我已经阅读了一个文本文件,该文件在全局环境中看起来不错:

enter image description here

注意:我在Windows上,换行符为\ r \ n。

看起来好像已经正确读取了,因为如果我在记事本++中查看文本文件,则会看到符号:

enter image description here

但是,如果我尝试使用cat写回文件,则会另外抛出{CR}个字节:

cat(txtFile, file="out.txt", append="FALSE")

enter image description here

这将导致结果文本文件显示为“双倍行距”。非常烦人,我不知道为什么cat()这样做。我也尝试过writeLines,但是每当它尝试将字符串写入文件时,它只会将{CR}放在{CRLF}之前。

有人知道如何停止这种行为吗?

1 个答案:

答案 0 :(得分:0)

此处的解决方案与此处的答案类似:R: Getting Unix-like linebreak LF writing files with cat()

    f<-file("out.txt", open="wb");
    cat(txtFile,file=f,sep="");
    close(f);

在记事本++中输出的结果文本文件: enter image description here