Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 226
EngrStudent Avatar asked Feb 02 '16 16:02

EngrStudent


People also ask

How do I set RStudio as default for R?

Use Windows Explorer (Finder on Mac) and navigate to the file BONUS/the_new_age. R . Now make RStudio the default application to open . R files (right click on the file Name and set RStudio to open it as the default if it isn't already)

How do I use .R files?

Type the relevant R function calls into the text file. To run an R command, put the cursor on the line of the command and then click the Run button at the top of the file window. Or just press CTRL-Enter.

How do I create a .R file?

Creating an R script You can open a new empty script by clicking the New File icon in the upper left of the main RStudio toolbar. This icon looks like a white square with a white plus sign in a green circle. Clicking the icon opens the New File Menu.


1 Answers

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.

like image 146
Christoph Avatar answered Oct 19 '22 22:10

Christoph