0

I have a brand new laptop with freshly installed R and RStudio.

When I open RStudio, the following error message pops up:

Warning message:
In normalizePath(path.expand(path), winslash, mustWork) :
  path[1]="C:/Users/tianj/OneDrive/??": The filename, directory name, or volume label syntax is incorrect

I checked environment variables, there are two entries that seemed to be wrong:

HOME          C:/Users/tianj/OneDrive/??
R_USER        C:/Users/tianj/OneDrive/??

I believe ?? here must be 桌面 which is actually Chinese alias of desktop. I googled a lot, it seems that the only way to modify env variables permanently is to create a .Renvrion file at ~/, however, in my case ~/ doesn't even exist. usethis::edit_r_environ also gives an error:

Error: [EINVAL] Failed to make directory 'C:/Users/tianj/OneDrive/??': invalid argument

I also tried to add env variables in Windows settings:

R_USER=C:/Users/tianj

but then another issue would appear:

'C:/Users/tianj/../Downloads/rest_of_the_path_to_file', probable reason 'No such file or directory'

R (or actually RStudio?) will add excess ../ in the path. So I have to remove env variables from Windows system.

Because of the issue, I cannot open or save any file using RStudio's interface, though relative R functions work without a problem.

How can I fix this issue? Is there another way to change default environment variables?

Tianjian Qin
  • 525
  • 4
  • 14
  • Can you be more explicit about exactly what version of Windows, R and RStudio you are using? – MrFlick Jul 01 '22 at 20:30
  • @MrFlick Latest stable Win11 21H2, RStudio 2022.02.3 492 and R 4.2.0 – Tianjian Qin Jul 01 '22 at 20:32
  • Does the error only appear in RStudio? Or does it also appear when you open R directly? – MrFlick Jul 01 '22 at 20:35
  • @MrFlick If I open R terminal in R installation folder, there is no error message – Tianjian Qin Jul 01 '22 at 20:37
  • So did you report this issue to RStudio but then end up closing the issue? https://github.com/rstudio/rstudio/issues/11373 – MrFlick Jul 01 '22 at 20:39
  • @MrFlick Exactly, that is my issue, I solved the issue in the issue, but my actual issue is not solved yet. – Tianjian Qin Jul 01 '22 at 20:45
  • Since this is an RStudio specific issue, I suggest you again use their github issue page to get help with your problem. Don't close the issue till it's solved. The default `R_USER` Windows paths are like "C:/Users/username/Documents" so you might try adding another folder to see if that fixes the auto `../` problem. I suggest you try to avoid OneDrive in these situations. – MrFlick Jul 01 '22 at 20:48
  • @MrFlick I guess Desktop on OneDrive is a new feature of Win11 which might have caused this issue. I don't really remember when I set local desktop to a cloud desktop. I will also try to switch back to local desktop to see whether I can solve the problem. The mixture of locale/language settings in win11 and onedrive may also be the source of the problem – Tianjian Qin Jul 01 '22 at 20:50
  • 1
    in case you set a ENV VAR in Windows you need to use Backslashes in there so instead of `R_USER=C:/Users/tianj` `R_USER` should be assigned `C:\Users\tianj` in the Environment Variables settings. Or you could even try something like `R_USER` and in the Value field you put: `%USERPROFILE%` but NOT within the RStudio/R session but in WINDOWS ENV Vars settings itself – GWD Jul 01 '22 at 21:14
  • @GWD manually adding `R_USER=%USERPROFILE%` and `HOME=%USERPROFILE%` in Environment Variables settings solved my problem, nice spot here – Tianjian Qin Jul 01 '22 at 21:33
  • 1
    Usually `HOME` is not required once you have decided to set `R_USER` since what R will attempt to do is derive R_USER from HOME - so you are sort of 'wasting' an ENV VAR definition in there. R_USER will be the one that drives most of the R search paths etc eg for package or lib installation folders or looking for your `~/.Rprofile` or `~/.Renviron` files and so on. Basically `~ = R_USER` – GWD Jul 01 '22 at 21:47
  • @GWD After encountering this problem again on a new device, I found that it was caused by OneDrive. On newer windows versions, newly installed windows, Documents folder will be linked to OneDrive. However, the Documents folder on my OneDrive was created in a system of non-English language, there is a feature of windows to accept different translation of Documents, and the underlying real path of the Documents was actually of another language, and this confused RStudio – Tianjian Qin Sep 26 '22 at 19:06

0 Answers0