How to get current working dir? I guess there should be a command like getcwd(), however, I can't find something like this in the documens.
How to change to another dir?
How to set default working dir when I start R?
version
_
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 3
minor 1.0
year 2014
month 04
day 10
svn rev 65387
language R
version.string R version 3.1.0 (2014-04-10)
nickname Spring Dance
Thanks!
You can also check your current working directory by running the command getwd() in the console. There are a number of ways to change the current working directory: Use the setwd R function. Use the Tools | Change Working Dir...
If we want to check the current directory of the R script, we can use getwd( ) function. For getwd( ), no need to pass any parameters. If we run this function we will get the current working directory or current path of the R script. To change the current working directory we need to use a function called setwd( ).
Get the current working directory: os. getcwd() returns the absolute path of the current working directory where Python is running as a string str . getcwd stands for "get current working directory", and the Unix command pwd stands for "print working directory".
The getwd() function in R can be used to display the current working directory. This simple function, which takes no arguments, returns the current working directory.
It is getwd()
It is setwd("path/to/new/dir")
Either via a Windows property, or via .Rprofile
etc, or (as I recall) by defining $HOME
which Windows does not set by default. See help(Startup)
.
As a complement to @Dirk's answer, I would like to add something that might be useful and is frequently overlooked.
It is possible to save the current working directory and set the new one at the same time.
Function setwd
returns the working directory so all you have to do is to save its value. This can be useful if you, at a later moment, need to return to the original working directory.
old_dir <- setwd("/path/to/new/dir")
#[run the code you want]
setwd(old_dir)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With