R is regularly pointed at a directory on your computer. You can find out which directory by running the getwd() function, and the function does not take any argument.
getwd in R
The getwd() is a built-in R function that returns an absolute filepath representing the current working directory of the R process. It does not take any parameter and returns the absolute filepath. To get the current directory in R, use the getwd() function.
The function does not take any parameter.
The getwd() function returns a character string or NULL if the working directory is not available. On Windows OS, the path returned will use “/” as the path separator and be encoded in UTF-8. The path will not have a trailing / unless it is the root directory.
If you want to get the current working directory in R, use the getwd() function.
As you can see that my current folder is the output, which means inside the R directory.
Default Working Directory in RStudio
RStudio employs the notion of a global default working directory. Normally this is the user home directory. When RStudio starts up, it does the following:
- Executes the .Rprofile (if any) from the default working directory.
- Loads the .RData file (if any) from the default working directory into the workspace.
- Performs the other actions described in R Startup.
When RStudio exits, and there are changes to the workspace, a prompt asks whether these changes should be saved to the.RData file in the current working directory.
This default behavior can be customized in the following ways using the RStudio Options dialog:
- First, change the default working directory.
- Enable/disable the loading of .RData from the default working directory at startup
- Specify whether .RData is always saved, never saved, or prompted for saving at the exit.
That is it for getwd() function in R.
Krunal Lathiya is an Information Technology Engineer by education and web developer by profession. He has worked with many back-end platforms, including Node.js, PHP, and Python. In addition, Krunal has excellent knowledge of Data Science and Machine Learning, and he is an expert in R Language. Krunal has written many programming blogs, which showcases his vast expertise in this field.