R Working Directory

R Tutorial – We shall learn how to set R working directory and get the value of R working directory using example R scripts.

R Working Directory – R Workspace

R Working Directory is the directory of R workspace. Any files in the R workspace could be referenced in R commands without specifying any relative path. While working with external input files or output files, knowing the R workspace helps in easing the efforts.

R Working Directory - R Workspace

Get Working Directory

Following is the syntax of R function to get working directory.

getwd()

Following is an Example R Script to get working directory :

 

Set Working Directory

Following is the syntax of R function to set working directory.

setwd(<complete_working_directory_path>)

The change to the working directory is only for scope of current running R Script. Once the current R script file execution is completed, the working directory reverts to default workspace.

Example R Script to set working directory

 

Conclusion :

In this R Tutorial, we have learnt how to set working directory and get the value of working directory using example R scripts.