我从终端复制代码以在此处发布。它的格式如下:如何将代码转换为更具可读性的表单R
> ddf2 = ddf[ddf$stone_ny>'stone',] # this is first command
> ddf2[!duplicated(ddf2$deltnr),] # second command
deltnr us stone_ny stone_mobility
4 1536 63 stone mobile
10 1336 62 stone mobile
前两行是命令,后面三行输出。但是,由于命令以'>'开始,因此无法从此处复制到R终端。我如何将其转换为:
ddf2 = ddf[ddf$stone_ny>'stone',] # this is first command
ddf2[!duplicated(ddf2$deltnr),] # second command
# deltnr us stone_ny stone_mobility
#4 1536 63 stone mobile
#10 1336 62 stone mobile
因此,它变得适合从这里复制。
我想:
text
[1] "> ddf2 = ddf[ddf$stone_ny>'stone',] # this is first command\n> ddf2[!duplicated(ddf2$deltnr),] # second command\n deltnr us stone_ny stone_mobility \n4 1536 63 stone mobile \n10 1336 62 stone mobile "
text2 = gsub('\n','#',text)
text2 = gsub('#>','\n',text2)
text2 = gsub('#','\n#',text2)
text2
[1] "> ddf2 = ddf[ddf$stone_ny>'stone',] \n# this is first command\n
ddf2[!duplicated(ddf2$deltnr),] \n# second command\n# deltnr us stone_ny stone_mobility \n#4 1536 63 stone mobile \n#10 1336 62 stone mobile "
但它不能得到粘贴到终端。
如果您使用的是RStudio,您可以在脚本编辑器区域轻松编写代码,并使用Ctrl + Alt + C注释掉结果。 – A5C1D2H2I1M1N2O1R2T1 2014-09-27 01:31:52
Ctrl + Alt + C在我的系统中不起作用(R studio 0.98。 501在Linux Debian稳定版上) – rnso 2014-09-27 01:42:04
也可以看看'Sublime Text 3' +'Enhanced R package'(适用于ST3)。多行编辑令人难以置信 – 2014-09-27 03:50:50