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?