+5 votes
in Programming Languages by (72.7k 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 (354k points)
selected by
 
Best answer

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


...