You can see the set of
directories S-Plus looks for with the search() command. It looks in each
directory, in order, so that if you created your own command named "+" --
and let me say I don't recommend it -- it would "mask" the existing "+"
command and yours would be used. The masked() command reveals the names
of items that appear in more than one directory. (If you're inside a function, there
are other places to look. See memory frames.)
The directory at the top of the list is called the working directory.
This is where new objects will be created. (Therefore it needs to be writeable.)
You can manipulate the search path with the attach() and detach()
commands. Of course you don't want to detach any of the built-in
directories, but you might imagine attaching a directory for a specific
project, doing a few things, then detaching it when you're done. Here's an example:
Notice that in S-Plus 6 you attach a directory that contains a .data directory. In earlier
versions you attach the _data directory itself.
If you want to create your own directory to store stuff, you need to create it with
S-Plus, not just under Windows. (This is new in S-Plus 6.0). Call createChapter()
to do this: you only have to do it once. (In addition to setting the directory up for S-Plus,
createChapter() will compile any C, C++ or Fortran code it finds lying around
in that directory.)
A library is a chapter created by someone else. The files in there look a little
different from the ones we make, but everything else acts the same. S-Plus ships with a
number of libraries (Mass, class, nnet, and so on). You attach these with the library()
command, which has essentially the same effect as the as the attach() command.
By default attach() and library() put new directories into position
2, right underneath your working directory,
Libraries are attached with File | Load Library.
The Search Path
Whenever you look for any S-Plus object -- anything you've created or anything built into S-Plus, even the "+" command -- the system goes looking for it in a series of directories. Some of these directories are called "chapters," others "libraries," and other directories are neither of these.
> attach ("d:/marines", pos=1) # Marine data now accessible
> attach ("d:/marinebkup", pos=2) # This one is in position 2
> newdata <- newdata # Copies an object from position 2 to position 1
> ls(,2) # Show objects in directory 2
> detach (2) # Detach backup directory
Using Chapters and Libraries (GUI)
Once you know the command-line story, attaching chapters and libraries from the GUI is simple.
In the Object Explorer, find the "SearchPath" icon in the left pane. Right-click on it and you can
create a new chapter or attach an existing one. I don't know how to detach a chapter from the GUI, though:
I believe you need the command-line detach() function for that.
Keeping your S-Plus Projects Separate
Each of your S-Plus projects can build up over time, and it's a good idea to keep them separate so you don't
accidentally overwrite data from one with data from another. There are at least three ways to do this.
> manpower
function(i = 1) {
attach ("d:/data/manpower/", pos=i)
invisible() # don't return anything
}
When I'm ready to start working on manpower, I type manpower() and that directory is attached.