R on Windows – weird user name gotcha

  • February 7, 2015
  • Steph
  • R

Oz and I being the lazy so and so’s that we are, share a profile and use it across all our devices. Our username is “Steph & Oz” which means the user folder that Windows has for us is C:UsersSteph & Oz. Having spaces and special characters is generally not recommended, and gives interesting issues when using R, primarily at initialization and when trying to do package installations.

By default, R will try make the user’s personal folder the directory which it works under, i.e. limiting its impact on the computer overall, but it’s Unix/Linux roots mean that it doesn’t like you doing whacky things like ampersands in folder names.

The result with ours is to cause this error on load:

Error installing package: Error: ERROR: no packages specified

‘Oz’ is not recognized as an internal or external command,

operable program or batch file.

R wd errror

R wd error screenshot

Now personally, I find the R documentation incredibly hard to understand and even the FAQs were rather opaque. So here is the simple solution to this issue – change the default working directory to a place with no spaces or odd characters. To get this change working automatically you need to download this Renviron.site file, update to your preferred location and copy it into C:Program FilesRR-3.1.2etc (or the relevant /etc folder for your R version). You may need to elevate your permissions whilst you do this – I’m assuming a home PC so it shouldn’t be a problem to do so.

https://gist.github.com/stephlocke/2d9315e15515ba7fe333

Warning

This will make all users of the computer have the same working directory, which means you can’t rely on the workspace being the same as how you left it. If you want to keep individual workspaces, change your username or create an alternative one to log into with R – I didn’t try changing the folder name as that way is likely to have lots of nasty side effects.

Search