[R-gregmisc-users] SF.net SVN: r-gregmisc: [1041] trunk/gdata/R/keep.R
Brought to you by:
warnes
|
From: <ar...@us...> - 2007-01-27 11:36:35
|
Revision: 1041
http://svn.sourceforge.net/r-gregmisc/?rev=1041&view=rev
Author: arnima
Date: 2007-01-27 03:36:34 -0800 (Sat, 27 Jan 2007)
Log Message:
-----------
Meaningful error message is given when requested object does not exist
Modified Paths:
--------------
trunk/gdata/R/keep.R
Modified: trunk/gdata/R/keep.R
===================================================================
--- trunk/gdata/R/keep.R 2007-01-27 11:35:12 UTC (rev 1040)
+++ trunk/gdata/R/keep.R 2007-01-27 11:36:34 UTC (rev 1041)
@@ -1,5 +1,3 @@
-# $Id$
-
keep <- function(..., list=character(0), sure=FALSE)
{
if(missing(...) && missing(list))
@@ -8,9 +6,13 @@
list <- c(list, names)
keep.elements <- match(list, ls(1))
- if(sure == FALSE)
+ if(any(is.na(keep.elements)))
+ stop("You tried to keep \"", list[which(is.na(keep.elements))[1]],
+ "\" which doesn't exist in workspace. Nothing was removed.", sep="")
+
+ if(sure)
+ rm(list=ls(1)[-keep.elements], pos=1)
+ else
return(ls(1)[-keep.elements])
- else
- rm(list=ls(1)[-keep.elements], pos=1)
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|