After upgrading RStudio in Ubuntu 22.04.1 (via rstudio-2022.12.0-353-amd64.deb
available at https://posit.co/download/rstudio-desktop/) the function style_selection
that is part of the styler
package has stopped working for me. The problem appeared while I was running styler
version 1.7.0 - after upgrading to current version 1.8.1, the problem described below persisted. I'm running R version 4.1.2.
It seems that, in contrast to typical R packages, styler
is a part of RStudio via Addins - for reference, in RStudio, clicks Tools, then Addins, then Browse Addins, and then Keyboard Shortcuts. Take note of the shortcut for the Addin named Style Selection - mine is ctrl+shift+a (this is possibly the default, but not certain).
Minimal example:
library(styler)
2+2 # take note of spacing
Highlight the above code and then hit the shortcut for Style Selection which for me is ctrl+shift+a. Expected result:
library(styler)
2 + 2 # take note of spacing
Instead of expected result, I receive the following error message:
> styler:::style_selection()
Using style transformers `styler::tidyverse_style()`
Error in `styler:::style_selection()`:
! No code selected
Run `rlang::last_error()` to see where the error occurred.
(Running rlang::last_error()
and rlang::last_trace()
don't seem to return anything meaningful.)
Any ideas? Thank you.
Update: Downgrading to rstudio-2022.07.2-576-amd64.deb
resolves the problem. However, running the current version would be preferred.
This is no longer an issue at least as of RStudio version 2024.04.2 Build 764.
https://posit.co/download/rstudio-desktop/