0

Is there code autoindentation possible in the R for Windows - Rgui? Cannot find it in the options (see below). It is quite uncomfortable having to press [tab] several times at the beginning of every row :-/ :-)

PS: please do not advise to use Rstudio, I didn't like it :) I like the simplicity of Rgui.

enter image description here

Tomas
  • 57,621
  • 49
  • 238
  • 373

1 Answers1

0

You can batch reformat it with the formatR package.

Assuming that you are using the File | New window and entering the code in that window then after entering the code:

  1. select all your code (ctrl-a) and send it to the clipboard (ctrl-c) and then

  2. set focus to the R console and enter this which will reformat the code in the clipboard and replace it on the clipboard with the reformatted code. (If you have already done this previously in the session you can just uparrow and enter to retrieve and run the prior instance.)

    library(formatR)
    tidy_source(file = "clipboard")
    
  3. finally set focus back to the code window, select everything (ctrl-a) and paste in the reformatted code (ctrl-v) to overwrite it with the reformatted code.

You could create an AutoHotKey script to automate the entire procedure but even if you don't it's only a few keystrokes or if you are using some text editor that you didn't mention there may be automation facilities in it.

G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341
  • No no no please, that's not a solution! I wan't help with writing, I want autoindentation embedded in the editor... – Tomas Aug 28 '18 at 18:02
  • The editor does not have that capability but you can still get the effect if you follow the instructions and if you are willing to do some work you can partially or entirely automate it. – G. Grothendieck Aug 28 '18 at 18:03
  • Man, I don't want to automate it, that's the thing! I just want a forecoming editor!! – Tomas Aug 28 '18 at 18:08