Setting a working directory: "Error in setwd: cannot change working directory" under "C:/Documents and Settings/..."

13,186

Seems to be an annoying Windows permissions issue; that's a legacy directory. There are 2.93 million Google hits along the lines of "Windows (7/)10: Access to the path 'C:\Documents and Settings' is denied". Look for advice in Windows forums, and check what the ownership and permissions on "C:/Documents and Settings/My Documents/..." are currently, and what they're supposed to be, and whether Administrator account is enabled. (Frankly not the best choice for the R install packages directory, but many installers use it, or default to it.)

  • Please confirm that setwd() works fine for a more harmless choice of directory, e.g. 'C:\Users\your_name\R'
  • Are you running R as Administrator or User?
  • Did you install R as Administrator or User? (which installer did you use, and which installer version/date? R-project's? Anaconda? another?)
Share:
13,186
Vanessa M
Author by

Vanessa M

Updated on December 05, 2022

Comments

  • Vanessa M
    Vanessa M over 1 year

    I was wondering why it won't let me change my working directory.
    I keep seeing this error:

    Error in setwd(dataDir) : cannot change working directory
    

    This is my code:

    dataDir <- "C:/Documents and Settings/My Documents/R/"
    setwd(dataDir)
    
    • tasasaki
      tasasaki almost 6 years
      Does the directory exist?
    • smci
      smci almost 6 years
      ...and does the user have read/execute permission on that directory?