Setting Working Directory setwd()

Hi, I've been trying to set my working directory to a folder on my desktop but I keep getting error messages, I've checked for spellings too. here is my code setwd ("C:/Users/pc/Desktop/divvyTrips")

R returns this;
Error in setwd("C:/Users/pc/Desktop/divvyTrips") : cannot change working directory

what am I doing wrong please?



to see where you are at the moment.

You are posting on the Posit Cloud category so if you are actually using that service you have to realize that the RStudio session runs on a server in the cloud and it doesn't have access to your local files so you can't set the working directory to a folder in your desktop.


You need select the folder for set the work directory.

1 Like

[1] "/cloud/project"

You are using Posit Cloud indeed, so as I said, you can't set your working directory to a folder on your computer because the program is running on a server in the cloud not in your local system and it doesn't have direct access to your local files.

The way to work on Posit Cloud is to upload the files you need to the server (with the "upload" button on the "Files" panel), so, you don't need to change the working directory.

1 Like

hello andresrcs, thanks for responding. Does that mean I can only set working directory to a folder on my desktop when Im using the desktop version of R? Ive just started learning r for data analytics. Thanks.

Yes, because a program running on a server on a different part of the world shouldn't have direct access to the files in your computer for security reasons. That is why you have to manually upload the files you need to the server.

1 Like

hi M, the folder is on my desktop

alright. Thanks. but how come there are tutorials out there teaching how to set working directory to a folder on your desktop, and the interface being shown isnt the desktop version of r? its the posit cloud interface... or im mistaking :thinking:

Most likely

Have in mind that you can also run RStudio Server on your own machine and in that specific case you obviously have access to the local files because they are in the server itself.

Also, be aware that manually setting your working directory is an outdated practice, it is better to use a "project oriented" workflow, you can read more about that here:

1 Like

alright. understood. I was actually trying to upload my files to the files panel but it was taking forever to upload so i just thought id set wd to desktop like i see in all these r tutorials :smiling_face_with_tear: :sweat_smile:
Thanks for coming through, i didnt even think id get a reply. ill go back to manually uploading them then

Thanks a lot! andre, thanks a lot. Ill always come back to you when i need help