+4 votes
in Programming Languages by (16.5k 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 in writeLines(line, fileout, sep = "\t") : 

  can only write character objects

1 Answer

0 votes
by (32.8k 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

+4 votes
1 answer
+3 votes
1 answer
+2 votes
1 answer