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() function in R
To get the current directory in R, use the getwd() function. The getwd() function returns an absolute filepath representing the current working directory of the R process.
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:
- 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.