+5 votes
in Programming Languages by (18.0k points)

I am using the writeLines() function to write data to a file. But the following code gives error. How can I fix the error?

writeLines(line, fileout, sep = "\t")  

Error:

Error in writeLines(line, fileout, sep = "\t") : 

  can only write character objects

1 Answer

+1 vote
by (41.9k points)

From the error message, it seems that the variable "line" is not a text; it contains numbers. You need to cast the variable line as a character to fix the error.

Make the following change in your code and it should work fine:

writeLines(as.character(line), fileout, sep = "\t")

Related questions

+5 votes
1 answer
+3 votes
1 answer
+4 votes
1 answer
+4 votes
1 answer
...