Ivan Krylov
2023-Nov-21 08:16 UTC
[R] [External] Re: Error in setwd(dir) when initializing R
On Tue, 21 Nov 2023 08:46:25 +0100 Ana de las Heras Molina <andelash at ucm.es> wrote:> > traceback() > 4: setwd(dir) > 3: .rs.onAvailablePackagesStale(reposString) > 2: .rs.availablePackages() > 1: .rs.rpc.discover_package_dependencies("3C994FEC", ".R")This is something that RStudio (not R itself!) does, but it shouldn't be failing. Here's what seems to be failing for you [*]: # prepare directory for discovery of available packages dir <- tempfile("rstudio-available-packages-") dir.create(dir, showWarnings = FALSE) # create a file in that directory saveRDS(Sys.time(), file = file.path(dir, "time.rds")) # (This doesn't fail because we keep executing the function, so the # directory must exist!) # move there owd <- setwd(dir) # this somehow fails Is it an option to disable OneDrive for the home directory? It's clearly doing something terrible to your temporary files. If not, it should be possible to create a separate temporary directory on your computer (the path must not contain spaces) and list it in the .Renviron file in the home directory as the TMPDIR variable: TMPDIR=C:/my/R/temp/directory See help(Startup) for more information on .Renviron. Alternatively, we may try to perform some debugging. If you set options(error = recover) and run .rs.availablePackages() again, it should fail and give you a debugger prompt. Choose the deepest option in the call stack and try to find out the value of the `dir` variable. Does dir.exists(dir) still return TRUE? Does setwd(dir) still fail? Can you open the directory in the Windows Explorer? The last but not the least, do you see some of the same problems if you launch Rgui.exe instead of RStudio? -- Best regards, Ivan [*] https://github.com/rstudio/rstudio/blob/45af283a7a5853399904ddc438f6cd89d9b5c137/src/cpp/session/modules/SessionPackages.R#L1625-L1636
Ana de las Heras Molina
2023-Nov-21 09:51 UTC
[R] [External] Re: Error in setwd(dir) when initializing R
Hi, I uninstalled onedrive, I eliminated all the folders and then reinstalled R and RStudio... but it is RStudio the one creating a folder called C:\Users\Ana\OneDrive - Universidad Complutense de Madrid (UCM)\Documentos. This is what I obtained with the debugging Error in setwd(dir) : no es posible cambiar el directorio de trabajo Enter a frame number, or 0 to exit 1: .rs.availablePackages() 2: .rs.onAvailablePackagesStale(reposString) 3: setwd(dir) Selection: 3Called from: .rs.onAvailablePackagesStale(reposString)Browse[1]> dir.exists(dir)[1] TRUEBrowse[1]> setwd(dir)Error durante el wrapup: no es posible cambiar el directorio de trabajo Error: no more error handlers available (recursive errors?); invoking 'abort' restart El mar, 21 nov 2023 a las 9:16, Ivan Krylov (<krylov.r00t at gmail.com>) escribi?:> On Tue, 21 Nov 2023 08:46:25 +0100 > Ana de las Heras Molina <andelash at ucm.es> wrote: > > > > traceback() > > 4: setwd(dir) > > 3: .rs.onAvailablePackagesStale(reposString) > > 2: .rs.availablePackages() > > 1: .rs.rpc.discover_package_dependencies("3C994FEC", ".R") > > This is something that RStudio (not R itself!) does, but it shouldn't > be failing. Here's what seems to be failing for you [*]: > > # prepare directory for discovery of available packages > dir <- tempfile("rstudio-available-packages-") > dir.create(dir, showWarnings = FALSE) > > # create a file in that directory > saveRDS(Sys.time(), file = file.path(dir, "time.rds")) > # (This doesn't fail because we keep executing the function, so the > # directory must exist!) > > # move there > owd <- setwd(dir) # this somehow fails > > Is it an option to disable OneDrive for the home directory? It's > clearly doing something terrible to your temporary files. If not, it > should be possible to create a separate temporary directory on your > computer (the path must not contain spaces) and list it in the > .Renviron file in the home directory as the TMPDIR variable: > > TMPDIR=C:/my/R/temp/directory > > See help(Startup) for more information on .Renviron. > > Alternatively, we may try to perform some debugging. If you set > options(error = recover) and run .rs.availablePackages() again, it > should fail and give you a debugger prompt. Choose the deepest option > in the call stack and try to find out the value of the `dir` variable. > Does dir.exists(dir) still return TRUE? Does setwd(dir) still fail? Can > you open the directory in the Windows Explorer? > > The last but not the least, do you see some of the same problems if you > launch Rgui.exe instead of RStudio? > > -- > Best regards, > Ivan > > [*] > > https://github.com/rstudio/rstudio/blob/45af283a7a5853399904ddc438f6cd89d9b5c137/src/cpp/session/modules/SessionPackages.R#L1625-L1636 >-- *Ana de las Heras Molina* Nutrici?n Animal Departamento de Producci?n Animal Facultad de Veterinaria Universidad Complutense de Madrid *Contacto*: 913943855/anaherasm at ucm.es [[alternative HTML version deleted]]
Ivan Krylov
2023-Nov-21 11:06 UTC
[R] [External] Re: Error in setwd(dir) when initializing R
? Tue, 21 Nov 2023 10:51:59 +0100 Ana de las Heras Molina <andelash at ucm.es> ?????:> I uninstalled onedrive, I eliminated all the folders and then > reinstalled R and RStudio... but it is RStudio the one creating a > folder called C:\Users\Ana\OneDrive - Universidad Complutense de > Madrid (UCM)\Documentos.Does Rgui.exe use a different home directory from RStudio? Perhaps you need not to reinstall RStudio (which deletes and recreates the program files which aren't damaged) but to wipe the profile (the settings somewhere under %APPDATA% or %LOCALAPPDATA%), but it pays to be extra careful about these directories. People at <https://community.rstudio.com/> may know more about that. I'm afraid I don't know how to disable OneDrive on a Windows 10 installation. If your university has a Microsoft support contract, it could be worth asking the Microsoft representative to fix OneDrive so that temporary files would work on it and telling them the steps to reproduce the problem.> Browse[1]> dir.exists(dir) > [1] TRUE > Browse[1]> setwd(dir) > Error durante el wrapup: no es posible cambiar el directorio de > trabajoWhat is the value of `dir` at this point? (What does print(dir) say?) Can you open this directory in Windows Explorer? If possible, could you please set your mailer to compose messages in plain text instead of HTML? The plain text versions of your messages that your mailer generates from the HTML messages are somewhat mangled: https://stat.ethz.ch/pipermail/r-help/2023-November/478593.html -- Best regards, Ivan