2

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)
smci
  • 32,567
  • 20
  • 113
  • 146
Vanessa M
  • 21
  • 1
  • 1
  • 2

4 Answers4

2

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?)
smci
  • 32,567
  • 20
  • 113
  • 146
0

There must be an error in the path. It should look like C:\<your_username>\Documents and Settings\My Documents

Or try

setwd("C:\\[your_username]\\Documents and Settings\\My Documents\\R")

lucascaro
  • 16,550
  • 4
  • 37
  • 47
Para
  • 1
  • 2
0

"Documents and Settings" is a directory that exists in really old versions of Windows (XP and earlier). In Windows 10, your user data is under C:\users\<username>, and your documents are in C:\users\<username>\Documents.

As far as R is concerned, under Windows 10 the home directory ~ maps to C:\users\<username>\Documents.

Hong Ooi
  • 56,353
  • 13
  • 134
  • 187
0

Run Rstudio as Admin. then run dataDir <- "C:/Documents and Settings/My Documents/R/" setwd(dataDirstrong text**)**