{"id":5283,"date":"2021-05-10T09:32:10","date_gmt":"2021-05-10T04:02:10","guid":{"rendered":"https:\/\/python-programs.com\/?p=5283"},"modified":"2021-11-22T18:49:06","modified_gmt":"2021-11-22T13:19:06","slug":"r-set-working-directory","status":"publish","type":"post","link":"https:\/\/python-programs.com\/r-set-working-directory\/","title":{"rendered":"R: Set working directory"},"content":{"rendered":"
In this article we are going to discuss about how we can set work directory R and also we will verify if that directory has been set perfectly or not. So, let’s start exploring the topic.<\/p>\n
R is an interpreted programming language which is created by Ross Ihaka and Robert Gentleman. This programming language and open source environment is used for statistical computing, graphical presentation, data analytics and scientific research.<\/p>\n
R studio is an\u00a0 Integrated Development Environment (IDE) which provides free and open source tools for Rn language.<\/p>\n
When working with R language sometimes we need to work with external files and for that we have to set that file directory as working directory otherwise the file won’t be accessible.<\/p>\n
So, let’s see how we can set a directory as an working directory in R studio.<\/p>\n
Steps to set working directory in R studio.<\/p>\n
By using For example, we have a directory If you want to set a directory as working directory but that directory does not exist then it will give Error.<\/p>\n For example, a directory Then<\/p>\n We can use If it returns the correct directory then the working directory has been set perfectly.<\/p>\n How to set work directory in R studio ? In this article we are going to discuss about how we can set work directory R and also we will verify if that directory has been set perfectly or not. So, let’s start exploring the topic. R is an interpreted programming language which is created by …<\/p>\nsetwd()<\/code> function we can set the working directory.<\/p>\n
Syntax : setwd<\/span>(<\/span>\"D:\/R_workingfile\"<\/span>)<\/span><\/pre>\n
\/Users\/BtechGeeks<\/code> and we want to set it as\u00a0 working directory then we can do it like this<\/p>\n
# command to set working directory.\r\n
setwd(\"
Users\/BtechGeeks\"<\/code>)<\/code><\/pre>\n
If the path does not exist :<\/h3>\n
\/Users\/Btech<\/code> which does not exists but we want to make it working directory.<\/p>\n
# Directory does not exist\r\nsetwd(\"\/Users\/Btech\")<\/pre>\n
# Raising error as directory does not exit\r\nError <\/span>in<\/span> setwd<\/span>(<\/span>\"\/Users\/Btech\"<\/span>)<\/span> :<\/span> cannot change working directory<\/span><\/pre>\n
Verifying the current working directory is set in R :<\/h3>\n
getwd()<\/code> function to check the current working directory.<\/p>\n
# It will give the current working directory\r\ngetwd<\/span>()\r\n>>
\"\/Users\/BtechGeeks\"<\/code><\/span><\/span><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"