reprex 设置输出宽度

reprex setting output width

如何设置 reprex 输出的宽度?

假设我有这样的代码:

(x <- 1:100)

我用 reprex::reprex(venue = "so")

得到了这个
(x <- 1:100)
#>   [1]   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17
#>  [18]  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34
#>  [35]  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51
#>  [52]  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68
#>  [69]  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85
#>  [86]  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100

我怎样才能增加输出的宽度来输出这样的东西

 [1]    1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50
 [51]  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100

可能的解决方案

我找到的一个选项,但我发现 "un-tidy" 是这个(在代码顶部包含 options(width = ...)。但我不希望它显示在输出中,我更喜欢在 reprex 调用中设置宽度。

options(width = 205)
(x <- 1:100)
#>   [1]   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50
#>  [51]  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100

reprex() 允许 knitr 的 opts-chunk,但我无法使用 reprex::reprex(venue = "so", opts_chunk = list(out.width = 205))(这可能与 #421 as pointed out here 有关(长行文本输出))

有更好的解决方案吗?

reprex 具有设置这些选项但不将它们包含在输出标记中的语法(有关示例,请参见 here)。在这种情况下:

reprex({

  #+ setup, include = FALSE
  options(width=205)

  #+ actual-reprex-code
  (x <- 1:100)

}, venue = 'so')

输出你想要的格式:

(x <- 1:100)
#>   [1]   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50
#>  [51]  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100

reprex package (v0.2.1)

创建于 2018-09-21