setwd() Error in R – cannot change working directory (2 Examples)

In this article you’ll learn how to avoid the “Error in setwd() : cannot change working directory” in the R programming language.

Example 1: Replicating the Error – cannot change working directory

setwd("C:/Users/Data Hacks/Desktop/My Directory")  # "My Directory" does not exist
# Error in setwd("C:/Users/Data Hacks/Desktop/My Directory") : 
#   cannot change working directory

Example 2: Solving the Error – cannot change working directory

setwd("C:/Users/Data Hacks/Desktop/")              # Use existing working directory

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top