rnahumaf
rnahumaf

Reputation: 501

Error in normalizePath(path.expand(path), winslash, mustWork) : path[1]="NA": The system cannot find the file specified

Each time after I open RStudio, the first line of code I enter will result in this warning:

Warning message: Error in normalizePath(path.expand(path), winslash, mustWork) : path[1]="NA": The system cannot find the file specified

This only happens once. As long as I don't close the document, for example, this warning will not show up anymore. However, if I close RStudio and open it again, the first time I run any code will reproduce the same warning.

This only happens for RStudio. If I use R instead, everything works normally.

I tried to supress this warning with supressWarnings(), suppressWarnings(suppressMessages()) or even invisible(capture.output(suppressWarnings(suppressMessages()))) to no avail.

I normally wouldn't care about warning messages, but since I'm working with RMarkdown, the warnings show up in the final document, so it's really annoying.

Thanks a lot for any help.

Upvotes: 9

Views: 14016

Answers (3)

kaiwu
kaiwu

Reputation: 21

my solution is to modify windows environment variables: control panel/system/advanced system settings

advanced system settings

  1. add an environment variable for R_USER

add an environment variable

variable name: R_USER

click "Browse Directory" and select the path where the application is installed, then click "OK".

for example:C:\Program Files\R\R-4.2.1

  1. modify the [Path]

Path in environment variables

click "Browse Directory" and select the path where the application is installed, then click "OK".

for example:C:\Program Files\R\R-4.2.1

Upvotes: 2

ekristof86
ekristof86

Reputation: 51

Some days ago, when I installed the latest versions of R and RStudio, I had the same warning message at each time after I open RStudio. The reason of the warning message was my account name in Windows which contains accented vowels. (I created an account name without accented vowels, then I installed R and RStudio again, and the warning message disappeared.)

However, I was able to avoid the problem with my old account name with accented vowels as follows:

  1. Install the R and RStudio in a folder to which you have admin rights. (I created a folder called R on my disk C, therefore its path is C:\R.)

  2. In RStudio, list the environment variables: Sys.getenv()

  3. The path of the environment variables that contain the account name with incorrect symbols shall be changed by creating a file called .Renviron.

    The .Renviron file shall be placed where you installed R. In my case it is C:\R. I chose this folder as the new path. Therefore, my .Renviron file contains the following three lines:

HOMEPATH="C:\R"<br>
HOME="C:\R"<br>
R_USER="C:\R"

(The .Renviron file was created in Notepad. When I saved the file I selected .Renviron as file name and All types was chosen as file type.)

  1. The default working directory can also be permanently changed as follows: In RStudio go to the menu: Tools / Global options / General. In the field "Default working directory (when not in a project)" choose a folder whose path does not have accented vowels. (I chose C:\R.)

  2. Finally, restart RStudio and the warning message disappears.

As a side note, I created empty .RData and .RHistory files in RStudio which are stored in the folder C:\R. By using these files, objects created in R and commands can be saved at the end of the working session.

Upvotes: 4

rnahumaf
rnahumaf

Reputation: 501

OK, I solved this by reinstalling both R and RStudio with their latest releases. The warnings have stopped.

Upvotes: 4

Related Questions