同时输出并在R中显示结果

时间:2017-02-22 15:30:30

标签: r export-to-excel

我想知道是否可以在控制台(Rstudio)中显示cat(...) “并且还将文件保存在< strong> .txt格式?

这是我的R代码:

   SOS = 33
    df = 12

  cat("\n","-------------", "\n" ,"SOS  ","  df","\n", "-------------","\n",
       SOS,"    ",df,"\n", "-------------", file = "Output.txt" )

1 个答案:

答案 0 :(得分:1)

SOS = 33
df = 12

#prepare your output
x = paste("\n","-------------", "\n" ,"SOS "," df","\n", "-------------","\n",
                                    SOS," ",df,"\n", "-------------", sep = "")

#display in console
cat(x)
#-------------
#SOS  df
#-------------
#33 12
#-------------

#Write to a txt file
cat(x, file = "output.txt")