简体   繁体   English

自动在R Console或RStudio的输出中添加注释掉签到

[英]Automatically add comments out sign in the output of R Console or RStudio

Currently we do the following: 目前,我们执行以下操作:

> head(mtcars,n=3)
               mpg cyl disp  hp drat    wt  qsec vs am gear carb
Mazda RX4     21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
Mazda RX4 Wag 21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
Datsun 710    22.8   4  108  93 3.85 2.320 18.61  1  1    4    1

Is there a way to tweak the Console (R or RStudio) so that it output: 有没有办法调整控制台(R或RStudio),使其输出:

> head(mtcars,n=3)
#               mpg cyl disp  hp drat    wt  qsec vs am gear carb
# Mazda RX4     21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
# Mazda RX4 Wag 21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
# Datsun 710    22.8   4  108  93 3.85 2.320 18.61  1  1    4    1

Using reprex package: 使用reprex包:

library(reprex)

reprex({head(mtcars, n = 3)}, comment = "#",  venue = "so")
# Rendered reprex is on the clipboard.

Result is saved to clipboard, when pasted it looks like this: 结果保存到剪贴板,粘贴后如下所示:

<!-- language-all: lang-r -->
  <br/>

  head(mtcars, n = 3)
#                mpg cyl disp  hp drat    wt  qsec vs am gear carb
# Mazda RX4     21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
# Mazda RX4 Wag 21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
# Datsun 710    22.8   4  108  93 3.85 2.320 18.61  1  1    4    1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM