Get and Set Working Directory in R Last Updated : 30 Jun, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we are going to see how to get and set a working directory in R Programming Language. How to Get Working directory: getwd(): The getwd() method is used to gather information about the current working pathname or default working directory. This function has no arguments. It returns an absolute pathname. It returns NULL in case there is not any working directory. getwd() Code: R # getting the working directory getwd() Output [1] "/Users/mallikagupta/Desktop"How to set up a working directory: setwd(): This method is used to set the specified pathname as the current working space directory of the R console. Syntax: setwd(dir) Where, dir is specify a working directory. The setwd() function allows us to move a hierarchy level up in the folder domain using the ".." argument in this method. Code: R # getting the working directory print ("Current working directory") getwd() # set working directory to its parents directory setwd("..") print ("Modified working directory") getwd() Output [1] "Current working directory" [1] "/Users/mallikagupta/Desktop" [1] "Modified working directory" [1] "/Users/mallikagupta" The subfolders can be easily accessed once the root directory has been set or is available by further specifying the character name of the sub-directory as a character string in the function arguments. R # setting parent directory setwd("/Users/mallikagupta/Desktop") # adding sub directory setwd("GFG") print ("Current working directory") # getting the working directory getwd() Output [1] "Current working directory" [1] "/Users/mallikagupta/Desktop/GFG" Comment More infoAdvertise with us Next Article Create and Save a Script in R M mallikagupta90 Follow Improve Article Tags : R Language R directory-programs Similar Reads Read all Files in Directory using R To list all files in a directory in R programming language we use list.files(). This function produces a list containing the names of files in the named directory. It returns a character vector containing the names of the files in the specified directories. If no files are present in the directory, 2 min read How to Fix in R: Cannot change working directory In this article, we focus on how we can fix the "cannot change working directory" error in the R programming language. One error that one may encounter in R is: Error in setwd("C:/Bhuwanesh/gfg") : cannot change working directory Such an error occurs when we try to set a working directory in R, but 2 min read How to Get the Current Working Directory in Golang? Getwd functionis used to get the current working directory in Golang, the function returns the rooted path name and if the current directory can be reached via multiple paths, the function can return any one of them. Syntax: func Getwd()(dir string, err error) The func returns two things the directo 1 min read How to remove a directory in R? In this article, we will discuss how to remove a directory using R programming language. To remove a directory in R we use unlink(). This function deletes the named directory. Syntax: unlink(directory-name, recursive = BOOLEAN) Parameter: directory-name: a character vector with the names of the dire 1 min read Create and Save a Script in R Scripting is a powerful way to save, organize, and reuse your code when working with R. Instead of typing commands interactively in the R console, you can write a series of commands in a script file (.R file) and execute them all at once. Saving your work as an .R script ensures reproducibility and 3 min read How to Display Current Working Directory in Linux | pwd Command The 'pwd,' which stands for "print working directory." In this article, we will delve into the 'pwd' command, exploring its functionality, usage, and various examples. It prints the path of the working directory, starting from the root. pwd is shell built-in command(pwd) or an actual binary(/bin/pwd 4 min read Like