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

同时输出并在R中显示结果,r,export-to-excel,R,Export To Excel,我想知道是否可以在控制台(Rstudio)中同时显示cat(…),以及“以.txt格式保存文件” 这是我的R代码: SOS = 33 df = 12 cat("\n","-------------", "\n" ,"SOS "," df","\n", "-------------","\n", SOS," ",df,"\n", "-------------", file = "Output.txt" ) double.cat=function(…,f

我想知道是否可以在控制台(Rstudio)中同时显示
cat(…)
,以及“
.txt
格式保存文件”

这是我的R代码:

   SOS = 33
    df = 12

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

double.cat=function(…,file){do.call(cat,list(…);do.call(cat,c(list(…),file=file))}
我使用
sink
将控制台输出打印到文件中。。。
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")