[R-gregmisc-commits] r2072 - pkg/gdata/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Feb 3 21:00:58 CET 2016
Author: warnes
Date: 2016-02-03 21:00:57 +0100 (Wed, 03 Feb 2016)
New Revision: 2072
Modified:
pkg/gdata/R/rename.vars.R
Log:
Improve logging and error reporting for remove.vars()
Modified: pkg/gdata/R/rename.vars.R
===================================================================
--- pkg/gdata/R/rename.vars.R 2015-11-24 17:58:02 UTC (rev 2071)
+++ pkg/gdata/R/rename.vars.R 2016-02-03 20:00:57 UTC (rev 2072)
@@ -44,14 +44,20 @@
}
-# GRW 2004-04-01
remove.vars <- function( data, names, info=TRUE)
+{
+ dsn <- deparse(substitute(data))
+ if (info) cat('\nChanging in',dsn, "\n")
+
+
+ flag <- names %in% colnames(data)
+ if(any(!flag))
+ warning("Variable(s) not found: ", paste(names[!flag], collapse=", ") )
+ if(any(flag))
{
- for( i in names )
- {
- if(info)
- cat("Removing variable '", i, "'\n", sep="")
- data[[i]] <- NULL
- }
- data
+ if(info) cat("Dropping variables:", paste(names[flag], collapse=", "), "\n\n")
+ for(var in names[flag])
+ data[[var]] <- NULL
}
+ data
+}
\ No newline at end of file
More information about the R-gregmisc-commits
mailing list