首页 文章

rstudio代码折叠就像在matlab GUI中一样

提问于
浏览
2

我通常使用matlab GUI进行编程,它具有非常好的代码折叠功能,如下所示:

%% This is one chunk of code I can fold just because I am using the %% comment format.
    matrix = [1 2 3; 4 5 6];
    vector = [1 2];
    ax = vector*matrix;

    %% This is another chunk of code I can fold because I am using the %% comment format.
    matrix2 = [7 8 9; 10 11 12];
    vector2 = [7 8];
    ax2 = vector2*matrix2;

正如matlab代码中所提到的,%%注释将立即为matlab GUI提供折叠选项,并且展开/折叠的加号/减号将出现在该行上,注释可见 .

无论如何在rstudio或一个好的R gui中实现这样的格式化?

我想要加/减功能,以及第一行注释是可见的,这样我就可以知道折叠的代码块中有什么 .

谢谢 .

GUI减去/加展开/折叠附加波纹管的照片:

minus folding

plus folding

当我在RStudio中尝试相同的方法时,似乎唯一的选择是编辑 - >折叠折叠/展开,但它隐藏了注释,并且它不像%%功能那样可自动化 . 在我的情况下更多的是一个问题,因为我使用X11所以我不想一直去编辑 - >折叠......而是在matlab中使用%%进行自动化 .

1 回答

  • 15

    你见过RStudio文档的code folding部分吗?你要求的一切都在其中描述 .

    要直接引用文档中最相关的部分,您可以通过 including at least four trailing dashes (-), equal signs (=), or pound signs (#) automatically creates a code section. 在任何注释行上创建代码部分 .

    如果这还不够清楚,也许我们可以通过例子学习:

    # Section One ---------------------------------
    
     # Section Two =================================
    
     ### Section Three #############################
    

    为了说明这实际上是进一步的,请检查以下两个屏幕截图 . 如果你得到不同的东西,我建议你更新RStudio,然后直接与RStudio的好人一起跟进:

    扩大:
    enter image description here

    倒塌:
    enter image description here

相关问题