How to prepend to a file (add at the top)

后端 未结 8 1007
逝去的感伤
逝去的感伤 2020-12-20 13:12

Imagine you have a file

sink(\"example.txt\")
data.frame(a = runif(10), b = runif(10), c = runif(10))
sink()

and would want to add some hea

8条回答
  •  不知归路
    2020-12-20 13:14

    In any language there is ultimately only one solution. And that is to overwrite the whole file:

    contents = readAllOf("example.txt")
    
    overwrite("example.txt", header + contents )
    

提交回复
热议问题