Skip to content

print.data.frame to string?

6 messages · Greg Snow, Jeff Newmiller, David L Carlson +1 more

#
What do you mean by prints?  You can use capture.output to get what
would regularly be printed to the screen into a text vector, or use
dput to get a version of an object that could be read back into
another R session.
On Thu, May 31, 2012 at 2:10 PM, ivo welch <ivo.welch at gmail.com> wrote:

  
    
#
capture.output(print(mydf))

note that df is a base function... best to not use it as a variable.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.
ivo welch <ivo.welch at gmail.com> wrote:

            
#
It will work if you paste a "\n" to the end of each line:

a <- data.frame(x=runif(4), y=runif(4), z=runif(4))
b <- capture.output(a)
c <- paste(b, "\n", sep="")
cat("Your data set is:\n", c, "\n")

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352