'Rstudio - cannot save files or open Rscripts 'The system cannot find the path specified'

Error when saving Rscripts

Error when opening Rscripts

Hi guys,

Have been stuck on this problem for the past year or so and would really appreciate any help. I am unable to save any Rscripts in Rstudio, as I keep getting the first error above. The one exception is, when running Rstudio with administrative permissions, - when saving into C:/Users, which is apparently the default working directory. I am also able to open Rscripts from C:/Users, but not from anywhere else. When I change my working directory using setwd(), Rstudio accepts the change but I am unable to save or open files in the new directory (or anywhere else).

I have tried fully uninstalling and reinstalling Rstudio and R, as well as adding the folder R and Rstudio are in, and my desired working directory folder into the 'PATH' variable in windows (through 'edit the system environmental variables'). But nothing seems to be working. Have also searched online pretty extensively but haven't managed to find a working solution so far.

I am using the latest 2021.09.1 Build 372 of Rstudio, and R 4.0.4. However, I have also faced the same problem on the last few versions of Rstudio and R over the past year as I have tried to update hoping that it would fix the problem but to no avail. I downloaded R and Rstudio from CRAN and the Rstudio website respectively.

Thanks a lot!



Solution 1:[1]

This exact thing happened to me. It turned out for me that when I updated my Window's environment variables, I added an extra slash for my HOME variable. This screwed things up with RStudio.

Search for "Edit the system environment variables" after pressing the Windows button and edit the HOME variable to make sure there is no trailing slash.

Good

C:\Users\leune006

Bad

C:\Users\leune006\

I hope that helps you and whoever else comes across this frustrating "bug"!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eric Leung