answersLogoWhite

0

How do you set working directory in RStudio?

Updated: 10/26/2022
User Avatar

Ahamsharma

Lvl 1
7y ago

Best Answer

The global default working directory is ~. Note that relative file references in your code will become invalid when you change working directories.

There are a number of ways to change the current working directory:

  • Use the setwd R function.
  • Use the Tools | Change working dir... menu (Session | Set working Directory on a Mac).
  • From within the File pane, use More | Set As Working Directory menu.

On Windows, you can set the working directory by changing the Start in field of your RStudio shortcut.

On a Mac you can drag/drop a folder onto the RStudio Dock icon to set the working directory.

Alternatively, open a terminal and specify the work directory:

$ open -a RStudio ~/projects/foo

$ open -a RStudio .

Note you can use the same terminal commands in Linux, however omit the trailing '.' in the second invocation. The first invocation sets "~/projects/foo" as the working directory, the second uses the current working directory.

When launched through file association, RStudio automatically sets the current working directory to the directory of the opened file. However, if RStudio is already running, opening another file via file association will not change the current working directory.

RStudio uses the .Rprofile file located in the current working directory. If there is no .Rprofile in that directory, the .Rprofile file located in the global default working directory (~/.Rprofile) is used instead.

The global .RData file will be saved in your new working directory when you exit RStudio.

User Avatar

Wiki User

7y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you set working directory in RStudio?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you identify the working directory in Linux?

The command 'pwd' will identify the full path of the present working directory.


The directory shown by pwd can be referred to as the current working dirctory?

pwd - means print working directory, which is always the current directory.


How do you make your home directory the working directory?

Use the 'cd' command without any target; that always puts you in the home directory which becomes by default the working directory.


What is the difference between the root directory your home directory and your working directory?

The root directory is the top level directory of the entire file system. Every branch starts from there. The current working directory is where you happen to be in the tree at the moment. If the root is always "/" and my process is in the directory /usr/local/bin/test/data, then the root directory is still "/" and my working directory is currently /usr/local/bin/test/data


What is the Linux command for displaying a working directory?

The command pwd displays your current/present working directory.


What is the pwd command in Linux?

The pwd command prints the working directory. The working directory is the directory you are "in", where operations on files that don't have an absolute path specified will be performed. For instance, if my working directory is /home/username/stuff, then the command echo "test" > test.txt would place the file test.txt in that directory.


What Linux commands make your home directory the working directory?

the command 'cd ~' will get you there .


How do you identify the working directory?

pwd


How do you find absolute path name of your home directory what is it on your system?

All you need is the PWD(Print Working Directory) command, this will list your current directory absolute path All you need is the PWD(Print Working Directory) command, this will list your current directory absolute path


How do you get the current working directory in PHP?

$curr_dir = getcwd();


What is the meaning of . and .. in unix?

The '.' refers to the current directory that you are working in, and the '..' refers to its parent (i.e. the directory just above the one you are now in).


What special permission should be set on public directories to prevent users from deleting files that others users have contributed?

In UNIX, this is the "sticky bit"... if set on a directory, only the owner of the directory, the owner of the individual file, and the superuser are allowed to delete files created in that directory. If not set, anyone with write permission on the directory can delete or rename files in it.