Writing variables to a file with writeLines

前端 未结 3 1446
误落风尘
误落风尘 2021-01-28 14:06

I found this link very helpful in understanding how to write lines to a file: Write lines of text to a file in R

Unfortunately though I\'m finding that I do not know how

相关标签:
3条回答
  • 2021-01-28 14:41

    In addition to using paste instead of cat, you could also possibly use cat directly in place of writeLines with the file argument to cat pointing to the connection. Or even less work (for the programmer, not the computer) is to not worry about the connection yourself but use the file and append arguments to cat to add to a file.

    0 讨论(0)
  • 2021-01-28 14:55

    Try substituting the "cat" function for the "paste" function:

    file.create("sample.txt")
    fileConn <- file("sample.txt")
    writeLines(c(paste(i, j, k, "07"),"1","41.6318 -87.0881 10.0"), fileConn)
    close(fileConn)
    
    0 讨论(0)
  • 2021-01-28 14:57

    Use paste instead of cat

    file.create("sample.txt")
    fileConn <- file("sample.txt")
    writeLines(c(paste(i, j, k, "07"),"1","41.6318 -87.0881   10.0"), fileConn)
    close(fileConn)
    file.show("sample.txt")
    
    0 讨论(0)
提交回复
热议问题