I\'m sorry to ask this question. I\'m very noob with R. I know there is a lot of threads which are related to the very same problem. I understood that we cannot export a tab
I think the most straightforward way to do this is using capture.output
, thus;
capture.output(summary(mylist), file = "My New File.txt")
Easy!
You can simply wrap your list as a data.frame (data.frame is in fact a special kind of list). Here is an example:
mylist = list()
mylist[["a"]] = 1:10
mylist[["b"]] = letters[1:10]
write.table(as.data.frame(mylist),file="mylist.csv", quote=F,sep=",",row.names=F)
or alternatively you can use write.csv (a wrapper around write.table). For the conversion of the list , you can use both as.data.frame(mylist)
and data.frame(mylist)
.
To help in making a reproducible example, you can use functions like dput
on your data.
I export lists into YAML format with CPAN YAML package.
l <- list(a="1", b=1, c=list(a="1", b=1))
yaml::write_yaml(l, "list.yaml")
Bonus of YAML that it's a human readable text format so it's easy to read/share/import/etc
$ cat list.yaml
a: '1'
b: 1.0
c:
a: '1'
b: 1.0
Check out in here, worked well for me, with no limits in the output size, no omitted elements, even beyond 1000
Exporting large lists in R as .txt or .csv
using sink
function :
sink("output.txt")
print(mylist)
sink()
cat(capture.output(print(my.list), file="test.txt"))
from R: Export and import a list to .txt file https://stackoverflow.com/users/1855677/42 is the only thing that worked for me. This outputs the list of lists as it is in the text file