R: Getting Unix-Like LF Strings Writing Files with cat ()

I am trying to write a character vector to a text file under Windows 7 / R 3.2.2 x64, and I want unix LF - not Windows CRLF:

v <- c("a","b","c")
cat(nl,file="textfile.txt",sep="\n")

writes

> a[CRLF] 
> b[CRLF] 
> c[CRLF]

cat(paste(nl,sep="\n",collapse="\n"),file="t2.txt")

writes

> a[CRLF] 
> b[CRLF] 
> c

I also tried write.table (eol = "\ n") - to no avail since it seems to use cat inside.

I was looking for other workarounds; I tried to find. in R \ src \ main \ scan.c, placing the corresponding code on line 387ff.

Who knows how I can get a UNF-like LF in my output file?

+4
source share
2 answers

"" ( "" ), :

v <- c("a","b","c")
f <- file("textfile.txt", open="wb")
cat(v,file=f,sep="\n")
close(f)
+2

@xb

converter <- function(infile){
    print(infile)
    txt <- readLines(infile)
    f <- file(infile, open="wb")
    cat(txt, file=f, sep="\n")
    close(f)
}
0

Source: https://habr.com/ru/post/1609963/


All Articles