Capture.output 忽略 r 中的控制台大小

Capture.output disregarding console size in r

我正在尝试使用 capture.output 来保存混淆矩阵,如下所示:

capture.output(result, file = "F:/Results/result.txt")

是否可以让 Capture.output 忽略控制台大小并假设它尽可能大(这样它就不会把东西分开)?

如果您想在我的特定数据上尝试,我将其作为 .rds 文件放在这里: https://upload.uni-jena.de/data/5f1045c6c0da81.96434142/result.rds

外观如下:

在小型控制台中(拆开):

Confusion Matrix and Statistics

           Reference
Prediction  ATCC25922 DSM1576
  ATCC25922         2       0
  DSM1576           0       2
  DSM3871           0       0
  DSM429            0       0
  DSM498            0       0
  DSM499            0       0
  DSM501            0       0
  DSM613            0       0
  DSM8696           0       0
  DSM9031           0       0
  Gr02              0       0
  Gr05              0       0
  Gr06              0       0
  Gr07              0       0
  Gr09              0       1
  Pak56             0       0
  Pak57             0       0
  Pak58             1       0
  Pak64             0       0
  Pak66             0       0
           Reference
Prediction  DSM3871 DSM429
  ATCC25922       0      0
  DSM1576         0      1
  DSM3871         2      0
  DSM429          0      2
  DSM498          1      0
  DSM499          0      0
  DSM501          0      0
  DSM613          0      0
  DSM8696         0      0
  DSM9031         0      0
  Gr02            0      0
  Gr05            0      0
  Gr06            0      0
  Gr07            0      0
  Gr09            0      0
  Pak56           0      0
  Pak57           0      0
  Pak58           0      0
  Pak64           0      0
  Pak66           0      0
           Reference
Prediction  DSM498 DSM499
  ATCC25922      0      0
  DSM1576        0      0
  DSM3871        0      0
  DSM429         0      0
  DSM498         0      0
  DSM499         0      3
  DSM501         0      0
  DSM613         0      0
  DSM8696        0      0
  DSM9031        0      0
  Gr02           0      0
  Gr05           0      0
  Gr06           0      0
  Gr07           1      0
  Gr09           1      0
  Pak56          0      0
  Pak57          0      0
  Pak58          1      0
  Pak64          0      0
  Pak66          0      0
...

在大型控制台中(一件):

Confusion Matrix and Statistics

           Reference
Prediction  ATCC25922 DSM1576 DSM3871 DSM429 DSM498 DSM499 DSM501 DSM613 DSM8696 DSM9031 Gr02 Gr05 Gr06 Gr07 Gr09 Pak56 Pak57 Pak58 Pak64 Pak66
  ATCC25922         2       0       0      0      0      0      0      0       0       0    0    0    0    0    0     0     0     0     0     0
  DSM1576           0       2       0      1      0      0      0      0       0       0    0    0    0    0    0     0     0     0     0     0
  DSM3871           0       0       2      0      0      0      0      0       0       0    0    0    0    0    0     0     0     0     0     0
  DSM429            0       0       0      2      0      0      1      0       0       0    0    0    0    0    0     0     0     0     0     0
  DSM498            0       0       1      0      0      0      0      0       0       0    0    0    0    0    0     0     0     0     0     0
  DSM499            0       0       0      0      0      3      0      0       0       1    0    0    0    0    1     0     0     0     0     0
  DSM501            0       0       0      0      0      0      2      0       0       0    0    0    0    0    0     0     0     0     0     0
  DSM613            0       0       0      0      0      0      0      3       0       0    0    0    0    0    0     0     0     0     0     0
  DSM8696           0       0       0      0      0      0      0      0       3       0    0    0    0    0    1     0     0     0     0     0
  DSM9031           0       0       0      0      0      0      0      0       0       2    0    0    0    0    0     0     0     0     0     1
  Gr02              0       0       0      0      0      0      0      0       0       0    3    0    0    0    0     0     0     0     0     0
  Gr05              0       0       0      0      0      0      0      0       0       0    0    2    0    0    0     0     0     0     0     0
  Gr06              0       0       0      0      0      0      0      0       0       0    0    1    2    0    0     0     0     0     0     0
  Gr07              0       0       0      0      1      0      0      0       0       0    0    0    0    1    0     0     1     0     0     0
  Gr09              0       1       0      0      1      0      0      0       0       0    0    0    1    0    1     0     1     0     1     0
  Pak56             0       0       0      0      0      0      0      0       0       0    0    0    0    0    0     3     0     0     0     0
  Pak57             0       0       0      0      0      0      0      0       0       0    0    0    0    0    0     0     1     1     0     0
  Pak58             1       0       0      0      1      0      0      0       0       0    0    0    0    1    0     0     0     1     1     0
  Pak64             0       0       0      0      0      0      0      0       0       0    0    0    0    0    0     0     0     0     1     0
  Pak66             0       0       0      0      0      0      0      0       0       0    0    0    0    1    0     0     0     1     0     2

设置options(width = 100)以扩大在控制台上打印对象时使用的一行的最大字符数。

options(width = 100)
capture.output(result, file = "F:/Results/result.txt")

注意:设置options(width = 100)后不要调整控制台window的大小。某些 R 控制台在调整大小时会自动更改值。