动态Rstudio代码段 [英] Dynamic Rstudio Code Snippet

查看:192
本文介绍了动态Rstudio代码段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我倾向于在代码中使用很多换行符,如下所示:

I tend to use a lot of line breaks in my code like the following:

# Data =========================================================================

整个地方注释的长度始终为80个字符(包括井号)。我想做的是为Rstudio编写一个代码片段,该代码片段将插入#标签,然后插入一个空格,然后允许用户键入一系列单词,然后插入另一个空格,最后填写一堆 =直到达到80个字符的限制。

Where the entire comment is always 80 characters long (including the hashtag). What I would like to do is write a code snippet for Rstudio that will insert the hashtag, then a space, then allow the user to type out a series of words, then insert another space, and finally fill in a bunch of "=" until the 80 character limit is reached.

我根本不了解摘要的工作原理,因此不确定这有多困难。

I'm not familiar with how snippets work at all so I'm not sure how difficult this is.

我有很多:

snippet lb
  # ${1:name}

但我不知道如何添加动态数字 =。另外,lb =换行符。

but I have no idea how to add a dynamic number of "=" signs. Also, lb = linebreak.

推荐答案

不幸的是,您无法使用摘要来实现此目的;代码段是一个文本模板,其中包含固定文本,带有用于用户插入的文本的插槽。

You can't do this with snippets, unfortunately; a snippet is a text template that contains fixed text with slots for user-inserted text.

RStudio内置了一个命令,可以执行非常相似的操作。从代码菜单中,选择插入节(或 Ctrl + Shift + R )。这将完全按照您的描述进行操作,但有两个小区别:

There is a command built into RStudio to do something very similar, however; from the Code menu, choose Insert Section (or Ctrl+Shift+R). This will do exactly what you're describing, with two small differences:


  1. 在打印前该行将扩展到5个字符边距(您可以在工具->全局选项->代码中调整打印边距。

  1. The line will extend to 5 characters before the print margin (you can adjust the print margin in Tools -> Global Options -> Code.

该行由-而不是 = 个字符。

以此方式标记的部分的一个优点是,您可以使用它们来折叠和浏览文件(在添加部分之后查看编辑器状态栏)。

One advantage to sections marked in this way is that you can use them to fold and navigate inside the file (look at the editor status bar after adding one).

这篇关于动态Rstudio代码段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆