My take is that this is the wrong question. The rm(list = ls(...))
construct is simply a nasty virus propagating by code copied between users.
What is the need for this construct?
- tidy workspace
- reduce memory use
- simplify the web of dependencies (
rm
won't help this)
Why wouldn't the designers of R provide a clean workspace to begin with? They do, it just gets misused and the default behaviour of Windows hides the details in unhelpful ways.
Why is the workspace not clean when R is started?
When R is started, it always works with a "current directory", that's like being "in a folder", if you ask for the "file1.iaf" you don't need to explicitly point to "C:/temp/myfolderofiafs/file1.iaf".
In unix that's just the place you're at when you type
R
and you can see it directly when you type
pwd
In Windows, it's the same at the command line (replace pwd with dir and look for "Directory of ..."), but when you "(double)click on the R shortcut" the system does the same for you, but where it starts is controlled by the "Properties" of the shorctut. You can see this by right-clicking on the shortcut, click "Properties" and see what the "Start in" field says. (It might be a system wildcard like %HOMEPATH% or whatever, but that probably stands for "C:/Users/username/Documents".)


R defaults to starting in one of your folders because it's the only place it can really know that is has permissions to do stuff.
I'm using Windows 8, this is all slightly different on Windows 3.1, 95, 98, NT, CE, 2000, XP, Vista, and 7, but covering all that can be left to google.
Have a look in that "Start in" folder, the chances are you won't see a file with the name ".Rdata" but that is because it is hidden. Start R, and run the following code before doing anything else:
list.files(all = TRUE)
Is there a ".Rdata" file?
(You can use "dir /a" to see it at the command line, or "ls -a" in unix for the same.)
When you start R that file gets loaded by default, as if you had done the following:
load(".Rdata")
That's why the workspace "needs cleaning up", but in my opinion you should delete that ".Rdata" file and rid your workflow of clunky hacks.
You can fix this from R, do this:
unlink(".Rdata")
and when you quit R, select "no" so that this hidden file does not get re-created again. If you accidentally create it, hunt it down and kill it again.
If you really want to save your entire workspace, use:
save.image("myentireworkspaceorperhapssomesensiblefilenameforit.Rdata")
or just a few objects from it:
save(keepme, keepme2, andme, file = "justsomeofmyclingyobjects.Rdata")
You can see the hidden ".Rdata" file in Windows itself by setting the View Properties for the folder (this is Windows 8 where I get to it via "View/Options 'Change folder and search options'"):

Choose "Show hidden files, folders and drives". I also strongly recommend that you unclick "Hide extensions for known file types" because the extension really is part of the file-name and hiding it sometimes just confuses everything. (Windows by default would make your file's real name "file.R.txt" if you tried to rename it from "file.txt" to "file.R" without this set).
There is more to this, in the "Target" field of the Properties of the shortcut you can add arguments such as "--no-restore" or "--no-restore-data".

This would also "fix" the ultimate problem above, but not in the right way IMO.
These arguments are available at the command line with (on Windows):
Rgui --help
but you'll need to use the full path or have R's bin/* folders in your path for that to work. See ?Startup
for a fuller discussion,