s-news
[Top] [All Lists]

Re: Question re objects() and remove()

To: "Peter Flom" <flom@ndri.org>
Subject: Re: Question re objects() and remove()
From: John Fox <jfox@mcmaster.ca>
Date: Thu, 16 May 2002 22:25:56 -0400
Cc: s-news@lists.biostat.wustl.edu
In-reply-to: <sce38d1e.059@MAIL.NDRI.ORG>
Dear Peter,

At 10:42 AM 5/16/2002 -0400, you wrote:
Unlike many, I like to keep just one workspace (perhaps this is only because I am new to S-Plus).

I thought a way to keep things a little organized would be to use object names that have one or more periods (.) for objects I don't want to delete; and then remove those without a period

But I can't figure out a way to do this.

Any help appreciated

You can use grep to filter the names. The exact form depends upon the version of S-PLUS. For example, the following expression works in S-PLUS 2000 for Windows:

        objects()[grep('*.*', objects())]

while the following works in S-PLUS 6.0 for Windows:

        objects()[grep('\\.', objects())]

Once you have the names, you can use remove to erase them -- e.g., remove(objects()[grep('\\.', objects())])

Note, however, that you'll also be removing some variables generated by S-PLUS with names including periods, such as .Last.value.

I hope that this helps,
 John
-----------------------------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox@mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox
-----------------------------------------------------


<Prev in Thread] Current Thread [Next in Thread>