I have a source code and want to output the result to a txt file. I manage to do this using the sink() function, like bellow:
source("Script sink test.txt", echo=F)
loopsinktestA <- file("SinktestA.txt")
sink(loopsinktestA, append=TRUE)
sink(loopsinktestA, append=TRUE, type="output")
Loop(MMatrix, "Parameter1", "Parameter2")
sink()
And all works well except one detail.
In my function output, there are some matrices, which tend to be big. When I put the results to appear on the console, the matrices tend to break according to with space on the screen, which is quite normal (if I have a bigger space, by pushing the help/graphs to the far right, more columns will appear before the matrix is broken). My problem is, the exact same thing happens in the SinktestA.txt
, basically, it mirrors what it would be expected in the console (I tried different exports and giving more and less space in the console, and the results in the output file broke the matrices in smaller or bigger number of columns).
E.g., this is how it's shown in the output due to the matrix not fitting all of the columns side by side:
Fi M Pi
As 16.06343 32.42949 0.00000
Ce 59.48432 39.78937 0.01211
Ri 0.01211 0.01211 0.00000
Ast 100.00000 100.00000 0.00000
Ts 25.11802 45.56349 0.00000
At 0.00000 0.00000 0.00000
Dm 7.17831 28.16850 0.00000
M Pi
As 0.00000 99.98789
Ce 0.00000 99.98789
Ri 99.98789 100.00000
Ast 0.00000 100.00000
Ts 0.00000 99.98789
At 0.00000 99.98789
Dm 0.00000 99.98789
Note: I actually have more columns, but for example purpose, le consider my space on the console just shows 4 columns and after has to break the matrix.
My question is, is there a way, or argument that I can use indicating the number of characters or something to be used before the matrices are broken in the output? Or a way to indicate the output should mirror the output results but not exactly its format?
Sorry if not that clear at any point.