Saving/loading RStudio settings with Command Prompt

12 October 2016

This one doesn't really deserve the title of 'project', but I thought I'd share it anyway.

I use RStudio to work with R. I am a huge fan of this piece of software for many reasons, one of which is the ability to change various settings of the code editor, such as its appearance and code auto-completion settings.

When using RStudio on the computers at the university, any changes made to these settings are wiped each time a user logs out of the machine. I quickly became tired of having to tick and untick multiple boxes each time I started a new RStudio session (call me lazy if you will; I prefer "economical"), so I decided to see if I could work out how to stop this from happening.

It turns out RStudio saves its settings in a folder called RStudio-Desktop, which is stored in the Local AppData section of the hard drive - which, on the university computers, is cleared for each fresh log-in.

Having logged in and changed the RStudio settings to my liking, I copied this folder to my personal drive (stored on the server rather than locally, so not wiped between sessions). I then wrote a short set of Command Prompt instructions to copy this folder into the Local AppData folder:

cd /d C:\Users\olj23\AppData\Local
xcopy H:\dos\R\Settings /e

(The a at the end is a response, All, to Command Prompt's question as to whether to overwrite files of the same name, in case I opened RStudio before running the code thus creating a new folder of the same name.)

This string of commands can be run from a desktop shortcut. The path below opens a Command Prompt window (and the /c closes it when finished) and runs the above commands in under half a second.

C:\Windows\System32\cmd.exe /c cd /d C:\Users\olj23\AppData\Local &
    xcopy H:\dos\R\Settings /e & a

Now whenever I want to open RStudio I can just click the neighbouring shortcut first et voila, my settings are loaded!

Maybe I should have studied graphic design