Isn't this better if you use DataSpell from Jetbrains instead of Pycharm?
I just do a lot of my R editing in PyCharm now and flip between terminals and RStudio. I was hoping DataSpell could unify that, but it's not ready.
The new RStudio IDE is promising, however.