New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in setwd(x) : cannot change working directory #51

Closed
bateyt opened this Issue Feb 2, 2014 · 21 comments

Comments

Projects
None yet
@bateyt

bateyt commented Feb 2, 2014

Software:
Windows 7 (32-bit)
R-3.0.2
RStudio (Version 0.98.501)
reports 0.2.0

First time trying to use reports package on new machine with Windows 7. Never run into this error (below) using Windows XP. Thanks.

library(reports)
new_report("new")
Error in setwd(x) : cannot change working directory

@trinker

This comment has been minimized.

Owner

trinker commented Feb 2, 2014

Is the session fresh? Does the path to the out directory contain spaces?

@bateyt

This comment has been minimized.

bateyt commented Feb 2, 2014

It was a fresh session. Unless I've specified otherwise, the out directory is the same as the working directory, correct? If so, then there are not any spaces. This morning, I had a thought to try creating a new report from the R GUI, rather than from within RStudio. While I had RStudio running, I started the R GUI, loaded the reports package, and typed "new_report('new')". Suddenly, that project opened in RStudio. I tested knitting the .*Rmd file and producing the other outputs, and it all worked fine. I happy to work with the 15-second extra step, but still don't know is causing the original issue in RStudio. Weird. Thanks.

@trinker

This comment has been minimized.

Owner

trinker commented Feb 2, 2014

Hmm. I have not updated to the newest RStudio because I noticed cut and paste issues as has been the case with previous version on some Windows machines.

I will leave this issue open and test this myself with the newest RStudio and try to track the problem down. Sounds, at the moment, to be something RStudio is doing in this latest release.

Can I ask you to test some of this theory by installing an older version of RStudio and try the same procedure. Here is the version I am using:

https://s3.amazonaws.com/rstudio-dailybuilds/RStudio-0.97.551.exe

@trinker

This comment has been minimized.

Owner

trinker commented Feb 2, 2014

Hmm just tried 0.98.501 and there were no problems. In RStudio what does getwd() give you?

@bateyt

This comment has been minimized.

bateyt commented Feb 3, 2014

Strange. Since you didn't run into a similar problem with RStudio 0.98, I wonder if it has something to do with Windows 7 or my new machine. At any rate, getwd() gives me the correct (default) working directory: "C:/Program Files/R/R-3.0.2". Also, from within RStudio, I can change the working directory with setwd(). Like I mentioned, for now, I can use the R GUI to set up the report directory, then do the actual work with RStudio. Thanks.

@trinker

This comment has been minimized.

Owner

trinker commented Feb 3, 2014

Can you try setting the working directory to somewhere other than the default working directory? Perhaps your desktop?

@Dasonk

This comment has been minimized.

Dasonk commented Feb 4, 2014

My guess is that you don't have write permissions in the folder you're trying to make the new report. I think this line is part of the problem:

https://github.com/trinker/reports/blob/master/R/new_report.R#L110

If you save the output of dir.create it will be TRUE if you were able to create the directory and FALSE if you aren't able to. If you save the output you can then either react to not being able to create the directory or possibly just give an error to the user explaining what is going on.

trinker added a commit that referenced this issue Feb 5, 2014

@trinker

This comment has been minimized.

Owner

trinker commented Feb 5, 2014

@dason thanks. I added

if (path == Sys.getenv("R_HOME")) stop("path can not be `R_HOME`")

early on which should take care of this.

@Dasonk

This comment has been minimized.

Dasonk commented Feb 5, 2014

I don't think that's the best fix. Honestly just detecting if the directory creation was successful is probably the easiest solution. If I get time later tonight I'll code up a fix and submit a pull request.

@bateyt

This comment has been minimized.

bateyt commented Feb 10, 2014

Tyler--

Your suggestion to change the default working directory solved the problem. Instead of using the main (installation) R directory, I changed it to a new folder in My Documents. Seems to work fine, now. Thanks.

@trinker

This comment has been minimized.

Owner

trinker commented Feb 10, 2014

Thanks for the feedback. Much appreciated. I'll close this for now then.

@trinker trinker closed this Feb 10, 2014

@Dasonk

This comment has been minimized.

Dasonk commented Feb 10, 2014

Oh yeah I was going to try to submit a pull request. Then I saw how many files needed to be modified and I got lazy. Maybe one day...

@SergeyBolotin

This comment has been minimized.

SergeyBolotin commented Feb 24, 2016

i got the same problem when use "~" in the path. If i use full path "C:/User...." there is not problems.

@SindhuraElluri

This comment has been minimized.

SindhuraElluri commented Jul 13, 2016

Hi, I ran into a similar problem.
Below is my file structure-> C:/Users/esindhura25/Desktop/Research/Southwesterndata/Grade6/(S34,S35)
ecah of S34 or S35 contain a log file. Below is the code I am trying to execute

setwd('C:/Users/esindhura25/Desktop/Research/Southwesterndata/Grade6')
students <- list.files()
for(std in students)
{
setwd(paste(std, '/log/', sep = ""))
unlink('*.ng3', recursive = FALSE, force = FALSE)
#setwd(paste('C:/Users/esindhura25/Desktop/Research/Southwesterndata/',fileDir, sep = ""))
}

But I am getting the below error . Please advise

Error in setwd(paste(std, "/log/", sep = "")) :
cannot change working directory

@heeby89

This comment has been minimized.

heeby89 commented Aug 26, 2016

@SindhuraElluri No one answered?

@trinker

This comment has been minimized.

Owner

trinker commented Aug 26, 2016

@heeby89 as far as I can tell that code has nothing to do with this package. I'm guessing @SindhuraElluri got a similar error and a google search lead here. That post probably belongs on stackoverflow not here if that is the case.

I agree that this behavior should be changed but don't forsee it until 2017. Pull requests are welcome. In the mean time it should work to explicitly change your working directory to the location you wish to add a project to (using setwd) before using new_report

@VytasHub

This comment has been minimized.

VytasHub commented Sep 8, 2016

getwd() didn't work for me too.

I was able to change my working directory throw settings.

Tool>Global Options...>General

@GabiUp2

This comment has been minimized.

GabiUp2 commented Apr 5, 2017

Have you tried opening your editor with administration priviliges? It worked for me.

@AshwInDu

This comment has been minimized.

AshwInDu commented Jul 13, 2018

I had the same problem with changing the working directory

With the same getwd commend giving me the following error:

setwd('F:/ContactFrom_v17/:')
Error in setwd("F:/ContactFrom_v17/:") : cannot change working directory

But @VytasHub @SindhuraElluri with simple understanding and manual effort I was able to change the directory
I am currently using RStusio 1.1.453 and it has a button on right of the window which is 'Go to directory'
Simply selecting that i was able to change the directory easily.

@ketra21

This comment has been minimized.

ketra21 commented Jul 24, 2018

RStusio in window 10.
@AshwInDu maybe your setwd("...") is not right. you can drop the second ":",change it like this:
setwd('F:/ContactFrom_v17')
have a try!

@fereshtehizadi

This comment has been minimized.

fereshtehizadi commented Jul 31, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment