1

Tibbles in the tidyverse makes it pleasing to view data tables. How do I print the nicely formatted text to a text file (or rich text file) for viewing, so that I don't have to open the IDE to view the formatted data strings?

For example:

library(tidyverse)

Var1 <- c("a", "b", "c", "d")
Var2 <- c(1.3243, 2.342342, 3.234234, 1.3425)
Var3 <- c(99, 100, 101, 102)

df <- as_tibble(data.frame(Var1,Var2,Var3))
print(df)

Here is the nicely formatted result:

# A tibble: 4 x 3
  Var1   Var2  Var3
  <chr> <dbl> <dbl>
1 a      1.32    99
2 b      2.34   100
3 c      3.23   101
4 d      1.34   102

How do I get this into a text file? Note that I'm not trying to write csv, I want to preserve the space formatting so that columns neatly align. Also, if there are other parameters that can customise the formatting that would be awesome!

Thanks!

alistaire
  • 42,459
  • 4
  • 77
  • 117
HackJob99
  • 89
  • 5

0 Answers0