rnorouzian
rnorouzian

Reputation: 7517

Simultaneously Output and show the result in R

I'm wondering if it would be possible to both show a cat(...) in the console (Rstudio) "AND ALSO" save the file in .txt format?

Here is my R code:

   SOS = 33
    df = 12

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

Upvotes: 1

Views: 73

Answers (1)

d.b
d.b

Reputation: 32558

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")

Upvotes: 1

Related Questions