Thread: [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. |
From: <ar...@us...> - 2007-01-28 10:42:27
|
Revision: 1042 http://svn.sourceforge.net/r-gregmisc/?rev=1042&view=rev Author: arnima Date: 2007-01-28 02:42:24 -0800 (Sun, 28 Jan 2007) Log Message: ----------- Throw warnings rather than errors Modified Paths: -------------- trunk/gdata/R/keep.R Modified: trunk/gdata/R/keep.R =================================================================== --- trunk/gdata/R/keep.R 2007-01-27 11:36:34 UTC (rev 1041) +++ trunk/gdata/R/keep.R 2007-01-28 10:42:24 UTC (rev 1042) @@ -1,14 +1,20 @@ keep <- function(..., list=character(0), sure=FALSE) { if(missing(...) && missing(list)) - stop("Keep something, or use rm(list=ls()) to clear workspace.") + { + warning("Keep something, or use rm(list=ls()) to clear workspace. ", + "Nothing was removed.") + return(invisible(NULL)) + } names <- as.character(substitute(list(...)))[-1] list <- c(list, names) keep.elements <- match(list, ls(1)) - 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="") + { + warning("You tried to keep \"", list[which(is.na(keep.elements))[1]], + "\" which doesn't exist in workspace. Nothing was removed.", sep="") + return(invisible(NULL)) + } if(sure) 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. |
From: <ar...@us...> - 2007-07-21 18:57:29
|
Revision: 1102 http://svn.sourceforge.net/r-gregmisc/?rev=1102&view=rev Author: arnima Date: 2007-07-21 11:57:25 -0700 (Sat, 21 Jul 2007) Log Message: ----------- Changed as.character(substitute()) to deparse(substitute()), following help(substitute) recommendation. Modified Paths: -------------- trunk/gdata/R/keep.R Modified: trunk/gdata/R/keep.R =================================================================== --- trunk/gdata/R/keep.R 2007-07-21 18:49:50 UTC (rev 1101) +++ trunk/gdata/R/keep.R 2007-07-21 18:57:25 UTC (rev 1102) @@ -6,7 +6,7 @@ "Nothing was removed.") return(invisible(NULL)) } - names <- as.character(substitute(list(...)))[-1] + names <- deparse(substitute(list(...)))[-1] list <- c(list, names) keep.elements <- match(list, ls(1)) if(any(is.na(keep.elements))) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ar...@us...> - 2008-01-29 11:09:45
|
Revision: 1239 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1239&view=rev Author: arnima Date: 2008-01-29 03:09:38 -0800 (Tue, 29 Jan 2008) Log Message: ----------- Added argument 'all'. Modified Paths: -------------- trunk/gdata/R/keep.R Modified: trunk/gdata/R/keep.R =================================================================== --- trunk/gdata/R/keep.R 2008-01-04 18:59:56 UTC (rev 1238) +++ trunk/gdata/R/keep.R 2008-01-29 11:09:38 UTC (rev 1239) @@ -1,4 +1,4 @@ -keep <- function(..., list=character(0), sure=FALSE) +keep <- function(..., list=character(0), all=FALSE, sure=FALSE) { if(missing(...) && missing(list)) { @@ -8,7 +8,7 @@ } names <- as.character(substitute(list(...)))[-1] list <- c(list, names) - keep.elements <- match(list, ls(1)) + keep.elements <- match(list, ls(1,all.names=all)) if(any(is.na(keep.elements))) { warning("You tried to keep \"", list[which(is.na(keep.elements))[1]], @@ -17,8 +17,8 @@ } if(sure) - rm(list=ls(1)[-keep.elements], pos=1) + rm(list=ls(1,all.names=all)[-keep.elements], pos=1) else - return(ls(1)[-keep.elements]) + return(ls(1,all.names=all)[-keep.elements]) } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |