Ana de las Heras Molina
2023-Nov-21 07:46 UTC
[R] [External] Re: Error in setwd(dir) when initializing R
Hello, Thank you all for your responses. When I initialize R, the folder in which it starts is: getwd() [1] "C:/Users/Ana/OneDrive - Universidad Complutense de Madrid (UCM)/Documentos" So it seems a problem with OneDrive -Kevin: I do not really understand your question... You mean if I set my working directory to my C:// or D:// folder in my computer? It doesn't work either. -Ivan: this is the message I got when running traceback(). So can I move the.Rdata file without affecting the work? -Luke: thank you for the idea, I will try it. Error in setwd(dir) : no es posible cambiar el directorio de trabajo> traceback()4: setwd(dir) 3: .rs.onAvailablePackagesStale(reposString) 2: .rs.availablePackages() 1: .rs.rpc.discover_package_dependencies("3C994FEC", ".R") Best, Ana El mar, 21 nov 2023 a las 0:43, <luke-tierney at uiowa.edu> escribi?:> On Mon, 20 Nov 2023, Ivan Krylov wrote: > > > On Mon, 20 Nov 2023 12:18:11 +0100 > > Ana de las Heras Molina <andelash at ucm.es> wrote: > > > >> Error in setwd(dir) : no es posible cambiar el directorio de trabajo > > > > If you run traceback() first thing after getting this error, does it > > say anything useful? (Anything besides "No traceback available" would > > count as useful.) > > > > Do you have a file named .RData in your home directory? If yes, it may > > help to move it away (or remove it if you don't use the saved session). > > Also check for .Rprofile or other profile that might contain a setwd() > call. Starting R with --vanilla should work if the issue is a startup > file. > > Best, > > luke > > > > > > > -- > Luke Tierney > Ralph E. Wareham Professor of Mathematical Sciences > University of Iowa Phone: 319-335-3386 > Department of Statistics and Fax: 319-335-3017 > Actuarial Science > 241 Schaeffer Hall email: luke-tierney at uiowa.edu > Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu >-- *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 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
This is likely tangential, but as a Linux user I have learned to avoid any directory name with - or ( or ) or other things, even spaces. Whether or not those are "valid", they seem to cause trouble. For example "-" can be picked up in bash scripts as a trigger for options. And in this case, it looks like the OP does not have control of the name. Sigh. John Nash On 2023-11-21 02:46, Ana de las Heras Molina wrote:> Hello, > > Thank you all for your responses. When I initialize R, the folder in which > it starts is: > > getwd() > [1] "C:/Users/Ana/OneDrive - Universidad Complutense de Madrid > (UCM)/Documentos" > > So it seems a problem with OneDrive > -Kevin: I do not really understand your question... You mean if I set my > working directory to my C:// or D:// folder in my computer? It doesn't work > either. > > -Ivan: this is the message I got when running traceback(). So can I move > the.Rdata file without affecting the work? > > -Luke: thank you for the idea, I will try it. > > Error in setwd(dir) : no es posible cambiar el directorio de trabajo> > traceback()4: setwd(dir) > 3: .rs.onAvailablePackagesStale(reposString) > 2: .rs.availablePackages() > 1: .rs.rpc.discover_package_dependencies("3C994FEC", ".R") > > > Best, > > Ana > > > El mar, 21 nov 2023 a las 0:43, <luke-tierney at uiowa.edu> escribi?: > >> On Mon, 20 Nov 2023, Ivan Krylov wrote: >> >>> On Mon, 20 Nov 2023 12:18:11 +0100 >>> Ana de las Heras Molina <andelash at ucm.es> wrote: >>> >>>> Error in setwd(dir) : no es posible cambiar el directorio de trabajo >>> >>> If you run traceback() first thing after getting this error, does it >>> say anything useful? (Anything besides "No traceback available" would >>> count as useful.) >>> >>> Do you have a file named .RData in your home directory? If yes, it may >>> help to move it away (or remove it if you don't use the saved session). >> >> Also check for .Rprofile or other profile that might contain a setwd() >> call. Starting R with --vanilla should work if the issue is a startup >> file. >> >> Best, >> >> luke >> >>> >>> >> >> -- >> Luke Tierney >> Ralph E. Wareham Professor of Mathematical Sciences >> University of Iowa Phone: 319-335-3386 >> Department of Statistics and Fax: 319-335-3017 >> Actuarial Science >> 241 Schaeffer Hall email: luke-tierney at uiowa.edu >> Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu >> > >