[Rd] String to list and visa versa

Vladimir Dergachev vdergachev at rcgardis.com
Tue Nov 14 22:46:06 CET 2006


On Tuesday 14 November 2006 12:28 pm, Prof Brian Ripley wrote:
> This approach won't work in very many cases (but then nor will write.csv).
>
> The safest way I know is to use serialize() and unserialize().  Next to
> that, deparse(control="all") and parse(text=) are quite good and give a
> human-readable character representation.
>
> If fidelity is not the main issue, as.character and toString spring to
> mind.  unlist is recursive, and is not going to come close to being
> faithful for other than very simple lists. And what if ',' is a character
> in one of the list elements?

Yes, but then one can replace ',' with something rarely used like \007.
I picked ',' because write.csv/read.csv worked before.

You are right, for storage serialize/unserialize seem best, however for 
manipulation one would usually prefer a well-defined format.
 
                         best

                             Vladimir Dergachev



More information about the R-devel mailing list