How to set default template for new “.R” files in rstudio

和自甴很熟 提交于 2019-11-30 16:57:00

问题


Background:
I like 'r'. I use Rstudio for it - it is a nice IDE. I use the revolution Analytics version of 'r', "revolution R Open".

I find that I type the same stuff in the annotation and structured programming regularly, and I want to save myself the re-typing.

Question:
How do I change the default file template so that the one I want, with some text already populated, comes up when I create a new blank R-script in Rstudio.

Clarifications:

  • I am not looking for this to be a manual process where I open one file, renaming it to a proper directory, and then work on it. I am looking to change the default so that this happens automatically.

Previous approach:

  • google
  • rstudio search (example)
  • search on stack-overflow
  • poking around rstudio menus/preferences

Thanks.


回答1:


Quite late and not really a template but I think the solution is close: go to

Tools => Global Options => Code => Tab Editing => Snippets "Edit Snippets".

Example:

snippet header2
    # Author:
    # Date: `r paste(date())`
    # --------------
    # Author:
    # Date:
    # Modification:
    # --------------

If you then type header {snippet} in a new script you get the text above with the date inserted automatically.



来源:https://stackoverflow.com/questions/35158708/how-to-set-default-template-for-new-r-files-in-rstudio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!