I have been struggling to make my R program print to a file. I have tried write, write.table, writeLines and cat but all to no avail, and I was hoping that someone could tell me where I am going wrong here.
Here is one attempt:
cat(searchn, file = "output.txt", sep = " ")
And here is another:
write.table(searchn, file = "output.txt", row.names = FALSE,
append = FALSE, col.names = TRUE, sep = " ")
But they all just end up with empty files. I know that searchn has an actual value though:
head(searchn)
factor(0)
1253 Levels: 1:12 1:56 ... X:93
Because of the fact the searchn has data in it, I am inclined to think that it is just a problem in my line of code that attempts to write to the file. Although I don’t know what factor(0) means and a quick google search didn’t turn much up. I would welcome an explanation on that front even if it is not causing my troubles.
Does anyone see what I am doing wrong here?
Your object
searchncontains no values. I know that because the result ofhead(searchn)is:which means you have a
factorof length zero, i.e. it’s empty.Although the object is empty, it still contains meta-information about the factor levels, for example. So printing this meta-information should work without a problem. For example, try: