Skip to content
Prev 82306 / 398502 Next

Writing a list to a file !

Here is a function I use to send lists to ASCII files.

list2ascii <- function(x,file=paste(deparse(substitute(x)),".txt",sep=""))
{
   # MHP July 7, 2004
   # R or S function to write an R list to an ASCII file.
   # This can be used to create files for those who want to use
   # a spreadsheet or other program on the data.
   #
   tmp.wid = getOption("width")  # save current width
   options(width=10000)          # increase output width
   sink(file)                    # redirect output to file
   print(x)                      # print the object
   sink()                        # cancel redirection
   options(width=tmp.wid)        # restore linewidth
   return(invisible(NULL))       # return (nothing) from function
}


I hope it's helpful.

To write it to a file that can be read by R, I would suggest using 
"dput" instead.

Regards,
Mike Prager
A Ezhil wrote: