Jean de Toit Jean de Toit - 4 months ago 11
R Question

R saving maximum of 10 characters per line

I am writing matrices to a text file. The problem is that any line longer than 10 characters is cut and added to the next line. I want it to all display in one line.

Example, basic info with a 1 x 12 matrix comes out as:

12
0 0 0 0 0
0 0 0 0 0
0 0


Goal:

12
0 0 0 0 0 0 0 0 0 0 0 0


Code:

# Create all the info
info <- paste(inputSize)
inTheta <- matrix (0,1,inputSize)

# Create the file
file.create(fileDir)

# Write the content
write(x=info,file=fileDir,append=TRUE)
write(x=inTheta,file=fileDir,append=TRUE)

Answer

There is the ncolumns parameter you can specify in the write function to make the line as long as you need:

write(m, "file.txt", append = T, ncolumns = 12)

This will give a file:

0 0 0 0 0 0 0 0 0 0 0 0