Output to the screen and output to a file according to the direction of the output.
The 1.cat function can be output to the screen or output to a file.
How to use: Cat (..., file = "", Sep = "", fill = false, labels = Null,append = False)
When there is a file, output to file. When there is no file, output to the screen.
Append parameter: Boolean value. True, the output is appended to the end of the file. FALSE to overwrite the original contents of the file.
Cat ("Hello") hellocat ("Hello", file= "D:/test.txt", append=t)
The 2.sink function redirects output results to a file.
How to use: sink (file = NULL, append = false, type = C ("Output", "message"),split = False)
Append parameter: Boolean value. True, the output is appended to the end of the file. FALSE to overwrite the original contents of the file.
Sink ("Hello.txt") # Redirects output to Hello.txtcat ("Hello") sink () # End redirect
The 3.writeLines function outputs a string vector to a file (overwriting the original content)
How to use: Writelines (text, con = stdout (), Sep = "\ n", usebytes = FALSE)
Text: string vector; Con: output file
A=c ("one","tew") writelines (A,con=" D:/test.txt", sep="\ t")
Problem: The original content is overwritten each time it is called?
The 4.write.table () function outputs the contents of the Dataframe to a file.
Usage:write.table (x, File = "", append = FALSE, quote = TRUE, Sep = "",eol = "\ n", na = "na", Dec = ".", Row.) Names = True,Col.names = true, Qmethod = C ("Escape", "double"),fileencoding = "")
M=matrix (1:12,nrow=3) df=as.data.frame (m) write.table (df,file= "D:/test.txt", append=t,row.names=f)
Output function Cat,sink,writelines,write.table of R language