tags:

views:

119

answers:

2

I asked this on Super User, but someone suggested that I take it here because there are many more R experts.

The question:

I have to keep navigating to my directory when I go to File > Change dir..., which is particularly annoying.

Does anyone know how to make R remember the previously used directory?

+1  A: 

There are a couple answers here.

Oh, sorry! I didn't notice at first that was your question.

(Non-useful edit by request.)

wallyk
A recursive answer, I like it ;)
ThisSuitIsBlackNot
Sorry, I can't seem to undo the down vote! It was an accident and my browser froze!!! Please edit so that I can vote up!!
Teef L
Great. Thanks! [[:
Teef L
+1  A: 

This depends on the system that your using. There are a few tricks to use but if your looking to run R from a system menu and have it remember the directory the quick answer is no that won't happen. Linux is pretty easy just navigate to the directory in the terminal first and that will solve the problem. I have no idea about macs, But I can talk about windows extensively. First if you navigate to the directory and save your workspace once then you can use the saved .RData file to double click and restore your workspace including current directory. My personal, and biased opinion is to use an editor like Notepad++ with NppToR that way when you spawn a Rgui window you inherit the active directory from the current script. It also provides a menu command to adjust the working directory to the current script's directory.

Another point is that you can always set the working directory with the setwd("path/to/dir/") command inside any R session on any platform.

Andrew Redd