In RStudio it is like:
- put your cursor anywhere in the file and press format shortcut: you will see a new line is created and selected. This almost always breaks your code.
- in a R file, press ctrl + A to select the whole file and press format shortcut: it is like what I expected, but a new line is added on top (why?).
- in a Rmd file, pressing ctrl +A won't work as the whole document is selected. I have to use expand selection (and shrink selection) multiple times to do the selection, and then press format shortcut.
(Furthermore: if your cursor unluckily is in a "deep" position of your current code chunk, you may have to press many times of expand selection. I counted 8 times just now.)
I use PyCharm and VS Code more often. Their format code feature is like:
- put your cursor anywhere in the file and press format shortcut;
- the whole file is formatted.
If possible, I'm glad to see a code format feature whose behavior is similar to that of PyCharm and VS Code, i.e. a feature with shortcut to format the whole current file or the current code chunk where the cursor is, without doing any selection.