Skip to content
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

RStudio setwd to mapped network drive not working Win10 #4030

Open
andzandz11 opened this issue Dec 12, 2018 · 27 comments
Open

RStudio setwd to mapped network drive not working Win10 #4030

andzandz11 opened this issue Dec 12, 2018 · 27 comments
Assignees
Labels
bug remote storage Dropbox, Google Drive, NFS, Microsoft OneDrive, Windows shared drives, network drives, etc. windows
Milestone

Comments

@andzandz11
Copy link

@andzandz11 andzandz11 commented Dec 12, 2018

issue has been reported in the past but without solution: https://support.rstudio.com/hc/en-us/community/posts/200652973-Network-Drives

has been reported here without solution:
https://stackoverflow.com/questions/25268582/rstudio-desktop-0-98-1006-for-windows-unable-to-access-mapped-network-drives

Version 1.1.453 – © 2009-2018 RStudio, Inc.
Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/538.1 (KHTML, like Gecko) rstudio Safari/538.1 Qt/5.4.1

setwd("Y:/")
Error in setwd("Y:/") : cannot change working directory

output from choose.dir()
grafik

same computer:
grafik

output from choose.dir()
grafik

grafik

@ronblum
Copy link
Contributor

@ronblum ronblum commented Dec 17, 2018

@andzandz11 Thank you for raising this issue. We will review it as we work on development of RStudio. Would you be willing to try out the preview of the upcoming release to see if the problem is resolved?

@JoFAM
Copy link

@JoFAM JoFAM commented Oct 22, 2019

Some more info, as we have the same problem on our university network. I've noticed a striking difference in the environment variables used by RStudio compared to R itself. The culprit is the HOME environment variable as reported by Sys.getenv(). This is given as

//files/loginname/home

in RStudio and

\files\loginname\home

in R itself.

Our workaround is to use save as, go to "This PC" and expand, go the the actual drive (H: for example) and find the folder from there. That works. Using save as, then use the shortcut "Home" in the explorer and then browsing to the correct subfolder doesn't.

This is using the latest version of RStudio (1.2.5001) and R 3.6.1

@kevinushey kevinushey added this to the v1.4 milestone Oct 22, 2019
@cbrnr
Copy link

@cbrnr cbrnr commented Jan 23, 2020

I have the same (or at least related) issue on my university network. The startup working directory is set to be the user's home drive mapped to Z:. The output of getwd() is "\\\\some.server.address/fs/home/user". Saving a script to that location does not work as it results in a location not found error. My workaround is to manually change to the mapped drive first with setwd("Z:"), which leads to a getwd() value of "Z:/". Only then does saving a script work correctly. Maybe RStudio should try to use mapped drive letters instead of the underlying network paths?

@rvino
Copy link

@rvino rvino commented Apr 15, 2020

Similar bug. My only solution has been after choose.dir() I right-click on 'This PC' and choose the option 'Map to Network Drive' and I map to the network drive. It still doesn't appear, but if I then close the pop-up box and reopen it with choose.dir() the network drive is there and is maintained after restarting Rstudio. I've only run into issues after updating the remote server I'm working on and have to do the above process again.

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Apr 15, 2020

I believe these issues are resolved in the preview release of RStudio (v1.3). Would you be able to download that and give it a shot?

@rvino
Copy link

@rvino rvino commented Apr 20, 2020

Upgraded to version 1.3.944 (R version 3.6.1) and rebooted remote. Same issue unfortunately.

@gwd666
Copy link

@gwd666 gwd666 commented Apr 24, 2020

@kevinushey can u pls check my new/additional comments back at #6598 (tested it with 1.3.947)
PS: maybe it is too minor a bug to be mentioned but I also did not find any comments on #6598 in the Release Notes of RS 1.3. (but could also be I just missed that), albeit the behavior is already different than before (in 1.2.5033), as I commented back at #6598.

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Apr 24, 2020

I think @gtritchie commented in the other post -- sorry, I was incorrect that this is fixed in the current v1.3 preview release; our goal is to bring the fix as part of a later patch release. Sorry for the trouble.

@lwatanabe
Copy link

@lwatanabe lwatanabe commented Jun 17, 2020

I found a way to trick R and RStudio into finding my network drive. Back story...the network drive was accessible through Windows Explorer but R could not see it. Even choose.dir() did not work. When I tried to map the network drive, it was already assigned.

My solution...save a script on the network drive and open the script directly (double-click). It opened with no problem. Now, RStudio can find the drive, even after restarting my machine.

@gwd666
Copy link

@gwd666 gwd666 commented Jun 18, 2020

@iwatanabe you basically are describing a variation of @cbrnr or @JoFAM comments and solutions for mapped networks on WIN
PS: R does not show issues with these drives it was only RStudio Versions 1.2.5033 to 1.3.959;
the 1.3. Patch versions so far seems to have solved that

@lwatanabe
Copy link

@lwatanabe lwatanabe commented Jun 18, 2020

I did try it in my R installation directly but choose.dir() did not show the drive. Even though I just installed them, I will check that the versions are the most recent with the appropriate patches. Thanks.

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Jul 16, 2020

I believe this is fixed in the latest v1.3 patch release (1.3.1056). https://rstudio.com/products/rstudio/download/#download

If you're still seeing issues with that build of RStudio, please let us know and we'll re-open this issue. Thanks!

@chrisk-edu
Copy link

@chrisk-edu chrisk-edu commented Jul 18, 2020

I am using 1.3.1056 and the behavior persists. setwd fails on a network share (using mapped drive, not UNC), but it works if double-clicking on file (as described before on lwatanabe variation).

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Jul 18, 2020

Thanks. Are you able to confirm whether you see the same behavior with R launched within a Windows command prompt, or within RGui (R's bundled R GUI)? Or is this specific to RStudio?

@williamlief
Copy link

@williamlief williamlief commented Jul 27, 2020

This error is persisting for me in Rstudio 1.3.1056. I can confirm that the problem is only in RStudio.

When I run choose.dir() in the R Gui (r version 4.0.2) I do see the network drives. When I run choose.dir() in RStudio I do not see my network drives. If I follow @lwatanabe post from june 17 by and directly open an r script or project that is on the network drive, then choose.dir in RStudio will show the network drives.

edit additional info: setwd("networkdrivepath") works in R GUI and Windows command prompt launched R. Does not work in RStudio 1.3.1056 : Error in setwd("networkdrivepath") cannot change working directory

@ronblum ronblum added qa repro and removed qa repro labels Jul 27, 2020
@R-Hannibal
Copy link

@R-Hannibal R-Hannibal commented Aug 12, 2020

Re-opening this ticket based on the feedback from @chrisk-edu & @williamlief that it is still occurring in 1.3.1056.

@kevinushey - milestone on this ticket is 1.4 and I'm not seeing a PR where it might have been fixed, am I missing something?

@R-Hannibal R-Hannibal reopened this Aug 12, 2020
@R-Hannibal R-Hannibal self-assigned this Aug 12, 2020
@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Aug 14, 2020

I think I might've erroneously concluded that a previous fix for the handling of UNC paths would have fixed this issue as well. See: #6598

@mikebessuille
Copy link
Contributor

@mikebessuille mikebessuille commented Aug 17, 2020

Leaving in 1.4 for now

@williamlief
Copy link

@williamlief williamlief commented Sep 3, 2020

Hi,
I wanted to follow up with some additional details. It appears that the problem actually happens when I am running as an administrator. R Gui is impacted in the same way. When I open either application with 'run as administrator' they are unable to find the network drives. If I run them normally (i.e. NOT as administrator) both applications see the network locations fine.

I had RStudio setup to always 'run as administrator' when I opened it from the taskbar, but when I open a project directly (by double clicking on it) it does not launch RStudio with administrator rights.

I am running Windows 10 (version 18363.959). Happy to provide more details/info if that is helpful or try and test additional things. I've had this issue on R 4.0.0 and 4.0.2 and RStudio 1.3.1056.

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Sep 3, 2020

Thanks! This is useful.

If the error reproduces in RGui, that likely implies the issue lies in R's own code, rather than something specific to RStudio. This limits our ability to solve the problem on the RStudio side, but if we're able to learn enough about what's going on we could attempt to supply a bug report + patch to the R Core team.

@andzandz11
Copy link
Author

@andzandz11 andzandz11 commented Sep 7, 2020

Thanks! This is useful.

No, this is not related to this bug.

If you run as another user your environmental variables change including your mapped drives. That is intended behaviour under Windows and affects all programs.

@williamlief
Copy link

@williamlief williamlief commented Sep 8, 2020

Thanks! This is useful.

No, this is not related to this bug.

If you run as another user your environmental variables change including your mapped drives. That is intended behaviour under Windows and affects all programs.

Thank you! For reference to others who find this thread in the future, running net use in the windows cmd prompt will show the mapped network drives. Comparing the output when running cmd as an administrator to without admin will show the differences in what drives can be accessed.

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Sep 8, 2020

@andzandz11: The thing that confuses me most about this bug is that, in theory, there shouldn't be anything RStudio-related here -- R's setwd() invokes only R's own code, and RStudio's own integration does (or, should not) make a difference here.

This is the R implementation for setwd():

https://github.com/wch/r-source/blob/f21fdfc8b6db5646326c52bcdcbd52ad6357716b/src/main/util.c#L776-L780

If you're able, it might be worth trying to compile a helper C / C++ program that tries to accomplish the same task, with more diagnostics. For example:

#include <Rcpp.h>
using namespace Rcpp;

#include <direct.h>

// [[Rcpp::export]]
void cd(std::string path) {
  int status = _chdir(path.c_str());
  if (status != 0) {
    const char* fmt = "error changing working directory [errno=%i]\n";
    Rprintf(fmt, errno);
  }
}

/*** R
cd("Y:/")
*/

I am not sure if there are any environment variables (or other application / system state) that could be influence the success or failure here, though.

@williamlief
Copy link

@williamlief williamlief commented Sep 8, 2020

TLDR I don't think there is any difference between R and RStudio. The problem I was seeing was coming from windows user environmental variables per @andzandz11 .

I had set RStudio to always open as an administrator when I opened it from the task bar, but NOT when I opened a project directly. This led me to believe that opening a project that existed on the network drive was somehow allowing RStudio to see the network drive. However, the actual problem was that I was running RStudio by default with the admin account (and the admin account doesn't have access to the network drive) but when I open a project directly RStudio launches only with regular user credentials and not as an admin.

When I ran R gui, initially I did not run it as an administrator and it could access the network drive fine.

I have checked and when I run R or RStudio as an Administrator they cannot see the network drive. When I run either as a regular user they both can access the network drive. Running net use in windows cmd with/without administrator level shows that windows cannot/can access the mapped network drives. You can use net use to give the admin account access to the network drive.

@kevinushey kevinushey modified the milestones: v1.4, v1.5 Sep 14, 2020
@Danny-dK
Copy link

@Danny-dK Danny-dK commented Feb 16, 2021

Not sure if this still helps (but the issue is still open). This is not a bug in Windows, this is intended behaviour in Windows. As mentioned by @williamlief, running Rgui or Rstudio in admin mode runs a different set of environment variables / runs in a different context. A quick search on the web "why cmd prompt not show network drives in admin mode" yields many links amongst which:

This happens with most windows software that have an elevated start (the search indicates a cmd prompt as this was the easiest search to get to the link, but applies to R and Rstudio).

Some users in this rstudio github issue report it from a university setting. If you have not downloaded and installed R and Rstudio yourself from the associated web pages (because you for example have not received admin or installation privileges from your university), you're most likely getting your R and Rstudio software packaged from the university. Most universities have a separate environment in which they offer packaged software to employees that can be installed, for example from something like a university "software center". These packaged software can be installed from a university link without admin rights required and have various settings pre-registered. If this is the case for you, you need to contact your own IT department to make them adjust these settings. Most likely they have set admin rights to the software to be able to install packages into the C-drive library. In my university we had many issues with the packaged university R and Rstudio versions, but were solved (by setting appropriate group policies and environment variables).

Again, this should not be treated imo as an R or Rstudio bug.

Hope this info helped.

@mikebessuille mikebessuille added the remote storage Dropbox, Google Drive, NFS, Microsoft OneDrive, Windows shared drives, network drives, etc. label Feb 17, 2021
@twang96
Copy link

@twang96 twang96 commented Jul 7, 2022

I found a way to trick R and RStudio into finding my network drive. Back story...the network drive was accessible through Windows Explorer but R could not see it. Even choose.dir() did not work. When I tried to map the network drive, it was already assigned.

My solution...save a script on the network drive and open the script directly (double-click). It opened with no problem. Now, RStudio can find the drive, even after restarting my machine.

This works. Try it.

@gwd666
Copy link

@gwd666 gwd666 commented Jul 7, 2022

@twang96

My solution...save a script on the network drive and open the script directly (double-click). It opened with no problem. Now, RStudio can find the drive, even after restarting my machine.

This works. Try it.

What you are witnessing as "working" is (most of the time) "just" a "fix" of the connection to a mapped network drive getting established;
meaning (ie if you witthness that sort of "bug" even when using a RStudio version that has all the necessary patches for the "real" bug that started this issue thread included) it will usually just be your network drive not being correctly connected to your machine - we also have that regularly (especially if there was/is a VPN involved during start-up and network drive connection, which was quite common in HO times, and led to Windows startup and network connection getting "out of sync" and therefore being "incomplete" there will often be a tiny red "x" visible near the drive letter, which is easy to miss).
So in that case when you save a script on your network share you are usually (mainly) fixing that network connection error, meaning for your current session you are clicking through to some network folder and that will usually suffice to make that connection share drive "live" or cleanly connect and RStudio and/or R (usually after a restart) will also pick up the network share correctly again.
Means, most of the time you can save yourself the extra effort of saving files, if your R/RStudio session is "unaware" of the network share, just close it click on the shared drive letter in your Windows Explorer (to fix that incomplete drive connection) and then open R/RStudio again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug remote storage Dropbox, Google Drive, NFS, Microsoft OneDrive, Windows shared drives, network drives, etc. windows
Projects
None yet
Development

No branches or pull requests