5

Does Rstudio have a mechanism to configure snippets of code, like Geany for example? For faster writing whole sections of user predefined frequent code. It is not exactly the same as TAB completion already built in rstudio.

Example by mimicking geany snippets

While snippet definition is like line below:

fun = %cursor% <- function(x, ...)\s{\n\n}\n

the usage is like this:

fun<TAB> (like bash style completion)
# will end up in following insertion:

 <- function(x, ...) {

}

so the user can then faster write the code by using her own snippets definition. And user can define ANY snippet of any size for completion by TAB.

It is not the Rstudio extract cmd, nieder Rstudio existing TAB context browser.

Petr Matousu
  • 3,120
  • 1
  • 20
  • 32

3 Answers3

8

Code snippets are available in RStudio version 0.99.

https://support.rstudio.com/hc/en-us/articles/204463668-Code-Snippets

Jim
  • 11,229
  • 20
  • 79
  • 114
1

I do not know of such functionality. However, if you want to quickly want to implement functionality with small changes you could also achieve this using functions.


Ok, your question is now clear to me. To my knowledge, Rstudio currently does not have this kind of functionality. You could, however, post a request on their forum for this feature. They respond quite actively to these kinds of requests, so you could give it a try.

Paul Hiemstra
  • 59,984
  • 12
  • 142
  • 149
1

The "Extract Function" feature in RStudio may be what you're looking for. Scroll down to the Extract Function section and accompanying screenshot on this page of rstudio.com's documentation: http://www.rstudio.com/ide/docs/using/source

The text of the section reads, "RStudio can analyze a selection of code from within the source editor and automatically convert it into a re-usable function. Any 'free' variables within the selection (objects that are referenced but not created within the selection) are converted into function arguments."

Also see this screenshot: http://www.rstudio.com/images/screenshots/rstudio-code-transform.png

Ryan
  • 911
  • 8
  • 7