[R] importing a list

Marc Schwartz (via MN) mschwartz at mn.rr.com
Wed May 10 20:41:02 CEST 2006


On Wed, 2006-05-10 at 13:19 -0500, Marc Schwartz (via MN) wrote:
> A search for the list2ascii() function, led me to this post by Mike
> Prager:
> 
> http://finzi.psych.upenn.edu/R/Rhelp02a/archive/66335.html
> 
> in which Mike specifically notes:
> 
> "To write it to a file that can be read by R, I would suggest using 
> "dput" instead."
> 
> 
> Thus, instead of using list2ascii() on your list object, use:
> 
> sink("YourTextFile")
> dput(YourListObject)
> sink()
> 
> You can then re-read the text file back into R using:
> 
> source("YourTextFile")

Actually, quick correction here. That should be:

  NewListObject <- dget("YourTextFile")

dget() will enable simple assignment of the textual input, whereas
source() will just evaluate it and assignment with source() creates a
list object, unless you use:
  
  NewListObject <- source("YourTextFile")$value

Marc




More information about the R-help mailing list