[R] Difficulties with setting working directory

Jim Lemon drjimlemon at gmail.com
Sat Oct 15 12:12:37 CEST 2016

Hi Anze,
I'm not sure that this will work on Windows, but you can create a
function named ".First" (note the leading period) with something like

.First<-function() setwd("C:/Users/anze")

To do this, start a session, enter the above line and then quit the
session, saving the current workspace. When you start R again, it
should change to that working directory. Of course you should make
sure what your home directory is.


On Sat, Oct 15, 2016 at 5:52 AM, Anže Dejak <anze.dejak at gmail.com> wrote:
> Greetings,
> Firstly, I'd hope this is the correct e-mail address to ask about specific
> problems refering to problems with R. If it isn't, I kindly ask of you to
> re-direct me to the correct contact person.
> So, the thing with my version of R (I'm using RStudio for R x64 3.3.0 in,
> currently, Windows 7) is, that I'm able to set the working directory
> temporary (through using setwd() function), but once I try to set it
> permanently (through "Session -> Set Working Directory -> Choose
> Directory..."), this error appears: Error in setwd("~/...") : cannot change
> working directory.
> As I've seen online on certain forums, the problem, supposedly, is that R
> in Windows is unable to recognize the ~ sign. But without it, I'm unable to
> set the working directory for more than a session.
> I'd hope you have a possible answer to this error.
> Thank you for your time and for reading this long e-mail and I hope you
> have a fine day, Anže D.
>         [[alternative HTML version deleted]]
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list