Can't set desktop folder as working directory in R Studio

In the past I've only used R, but I want to use RStudio to teach an intro stats course. However, I'm having trouble getting certain basic commands to work properly in RStudio, even though they work fine in R. For example, I have a folder on my desktop named "Folder."

In R, I can easily set this as the working directory:

getwd()
[1] "/Users/username"
setwd("Desktop")
getwd()
[1] "/Users/username/Desktop"
setwd("Folder")
getwd()
[1] "/Users/username/Desktop/Folder"

However, in RStudio, if I try to set a desktop folder as the working directory, it just reverts to my username folder:

setwd("/Users/username/Desktop")
getwd()
[1] "/Users/username/Desktop"
setwd("Folder")
getwd()
[1] "/Users/username"

I can create a new folder in my username folder as the directory, along with any folder within that new folder. But any time I use the desktop (or any other pre-existing folder in my username folder, like "Downloads" or "Documents") within the middle of a working directory path, RStudio reverts to the username folder.

Any idea what is going on here? I'm using MacOS and I've reinstalled both R and RStudio.

Using UI does it works?

Clicking on the Desktop folder produces a pop-up error saying “File Listing Error, Error navigating to ~/Desktop: Operation not permitted.” Strange. Thanks for the suggestion!

Aha, I got it... It was a system problem.

System Preferences > Security & Privacy > Privacy > Files and Folders
(R had permission to access folders but RStudio did not, what a weird default)

Thanks for your comment, that helped!

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.