Write the output of str() to a text file?

Viewed 67

str() is useful for understanding large, odd-shaped named lists. But sometimes we wish to search the output, especially if it's large.

When writing to a file like so

library(dplyr)
iris %>% str %>% as.character %>% writeLines("iris.txt")

The text file doesn't contain the expected content (although the file itself is created)

How can we write the exact content produced by str() in the console in a text file?

1 Answers

How about using capture.output()?

capture.output(str(iris), file = "iris.txt")
Related