How do you sink input and output to a text file in R?

前端 未结 2 1755
余生分开走
余生分开走 2020-12-25 15:34

How do you sink both the console input and the console output to a text file? Take the following code:

sink(\"temp.txt\")
1:10
sink()

It wi

相关标签:
2条回答
  • 2020-12-25 15:54
    library(TeachingDemos)
    
    txtStart("temp.txt")
    1:10
    txtStop()
    

    The text file now looks like

    > 1:10
     [1]  1  2  3  4  5  6  7  8  9 10
    
    0 讨论(0)
  • 2020-12-25 15:59

    If you save an R script file instead of inputing your commands into an interactive session, you can also run the following from the command line (on *nix systems):

    R --no-save --quiet < /path/to/script.R > /path/to/output.txt
    

    This will create the file "output.txt" and save all input (including comments) and output from the R script into it.

    0 讨论(0)
提交回复
热议问题