[R] R equivalent of Python str()?

Ernest Adrogué nfdisco at gmail.com
Wed Feb 8 10:53:17 CET 2012


 8-02-2012, 09:45 (+0100); Martin Maechler escriu:
> >>>>> "R Michael Weylandt <michael.weylandt at gmail.com>"
> >>>>> <michael.weylandt at gmail.com>
> >>>>>     on Tue, 7 Feb 2012 20:23:57 -0500 writes:
> 
>     > Possibly as.character() is what the OP was seeking
>     > Michael
> 
> or   format()   which is closer for numeric data
> 

Thanks for the suggestions, but none of these appears to do what I
need. Take a table such as

> a <- as.table(c(A=450,B=12))
> a
  A   B 
450  12 

The string that print() prints is " A B \n450 12 \n". Once you have
the string you can print it with cat() and get the same result as with
print().

> cat("  A   B \n450  12 \n")
  A   B 
450  12 

The function that I was looking for was one that given the table a in
the example would return the string described above. Apparently,
capture.output() can be used for that, although it returns the string
split into lines they can be joined together easily. So, case closed
:)

-- 
Bye, 
Ernest



More information about the R-help mailing list