ARCHIVED: In R, why do I get an error when specifying a directory path in Windows?

This content has been archived, and is no longer maintained by Indiana University. Information here may no longer be accurate, and links may no longer be available or reliable.

In Windows, when specifying a directory path in R (e.g., to set the working directory or load a data set), you will get an error if the directory path contains a backslash:

  > setwd("C:\R files")
  > Error: '\R' is an unrecognized escape in character string starting "C:\R"

In R, a single backslash is an escape character, and using it for directory paths will always produce an error. To specify directory paths correctly in R, you have two options:

  • Use two backslashes instead of a single one:
      > setwd("C:\\R files")
  • Use a forward slash:
      > setwd("C:/R files")

If you have questions about using statistical and mathematical software at Indiana University, contact the UITS Research Applications and Deep Learning team.

This is document azzp in the Knowledge Base.
Last modified on 2023-05-09 14:39:17.