How do I store the result of str () as a string in R?

I am learning Shiny by developing a brilliant application that generates a report on a selected csv file. I was able to output the head and summary of the dataFrame. Nevertheless, I stuck to preserve representation str () df, since the function str () returns a NULL, instead of printing material on the console.

Is there any workaround for storing str () for a variable for the purpose of representing it in a brilliant application?

+3


source to share


1 answer


capture.output

will create a character vector (one element for each line printed to the console). If you want it on the same line, you can link it to paste(foo, collapse="\n")

.



data(iris)
(out <- capture.output(str(iris)))
out2 <- paste(out, collapse="\n")

      

+13


source







All Articles