[R] Writing output into a file

Rui Barradas rui1174 at sapo.pt
Mon Feb 13 00:07:30 CET 2012


Hello

One way is

# Write the file
save(myList, file="test1.bin")

# Reload the data, under the same name, 'myList'
load(file="test1.bin")

Another way is a bit more complicated

# Open a file connection and write the list to it (using  comma as
separator)
fileCon <- file("test2.txt", open="wt")
lapply(myList, function(x) writeLines(paste(x, collapse=","), con=fileCon))
close(fileCon)

# Load the data, maybe under another name
strsplit(readLines(con="test2.txt"), split=",")

If you use the first method, the list is retrieved as it was.
If you use the second, you lose the list's members' names.

Hope this helps,

Rui Barradas


--
View this message in context: http://r.789695.n4.nabble.com/Writing-output-into-a-file-tp4382243p4382310.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list