[Rd] RODBC and utils:object.size
I would like to note that utils::object.size fails on RODBC connection objects. > DB<-RODBC::odbcConnect("internal") > utils::object.size(DB) Error in utils::object.size(DB) : object.size: unknown type 22 > I took a brief look at do_objectsize in the source code, and could not figure out how it dealt with new classes of objects. i.e. if someone defines a new class (such as "RODBC") are they supposed to define a size method for the class? My current workaround for listing object sizes is to drop RODBC objects from Petr Pikal's original ls.objects() function: ls.objects<-function (pos = 1, order.by,...) { napply <- function(names, fn) sapply(names, function(x) fn(get(x,pos=pos))) names <- ls(pos = pos,...) obj.class <- napply(names, function(x) as.character(class(x))[1]) obj.drop <- match("RODBC",obj.class) obj.class <- obj.class[-obj.drop] names <- names[-obj.drop] obj.mode <- napply(names, mode) obj.type <- ifelse(is.na(obj.class), obj.mode, obj.class) obj.size <- napply(names, object.size) obj.dim <- t(napply(names, function(x) as.numeric(dim(x))[1:2])) vec <- is.na(obj.dim)[, 1] & (obj.type != "function") obj.dim[vec, 1] <- napply(names, length)[vec] out <- data.frame(obj.type, obj.size, obj.dim) names(out) <- c("Type", "Size", "Rows", "Columns") if (!missing(order.by)) out <- out[order(out[[order.by]]), ] out } Leif S. Kirschenbaum, Ph.D. Senior Yield Engineer Reflectivity, Inc. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Request for showWarnings parameter for write.table
Madams & Sirs, I use write.table to write CSV files to generate reports for my colleagues to open in their spreadsheet application of choice. I often append data of dissimilar structure to the same file, i.e. a few summary lines and then additional data of some number of columns. Normally write.table produces: > write.table(etest[,writevars],file=fname,row.names=FALSE,col.names=TRUE, append=TRUE,sep=",") Warning message: appending column names to file in: write.table(etest[, writevars], file = fname, row.names = FALSE, Therefore I resort to: > options(warn=-1) > write.table(etest[,writevars],file=fname,row.names=FALSE,col.names=TRUE,append=TRUE,sep=",") > options(warn=0) However I thought that perhaps a parameter such as included for dir.create would be more elegant: > write.table(etest[,writevars],file=fname,row.names=FALSE,col.names=TRUE, append=TRUE,sep=",",showWarnings=FALSE) where showWarnings would default to TRUE. Please cc: replies to [EMAIL PROTECTED] Thank you. Leif Kirschenbaum Senior Yield Engineer Reflectivity, Inc. (408) 737-8100 x307 [EMAIL PROTECTED] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] request to add "..." to cat(ngettext in "warnings" function
Madams & Sirs, I am working on porting some R code to one of our servers to run under web or crontab direction. With that in mind I have been working on directing informative, warning, and error messages to outputs as I require. I would like to suggest a change to the "warnings" function; that the passed arguments be enabled to all instances of "cat" in the function, specifically that the "cat(ngettext" have the ellipsis added to the call so that users may be able to call warnings as "warnings(file=stderr())" and the function will write all text to the stderr stream. As it is written today, the text "Warning message:" is written to the console output no matter what. Since I am writing only output to the console output which is to be passed to the calling script (PHP, shell script, etc.) I need to divert all other messages to the stderr which I log using sink, so I need all of warnings' output to go to stderr. Thank you. warnings<-function (...) { if (!exists("last.warning", envir = .GlobalEnv)) return() last.warning <- get("last.warning", envir = .GlobalEnv) if (!(n <- length(last.warning))) return() names <- names(last.warning) cat(ngettext(n, "Warning message:\n", "Warning messages:\n"),...) for (i in 1:n) { out <- if (n == 1) names[i] else paste(i, ": ", names[i], sep = "") if (length(last.warning[[i]])) { temp <- deparse(last.warning[[i]]) out <- paste(out, "in:", temp[1], if (length(temp) > 1) " ...") } cat(out, ..., fill = TRUE) } } Leif Kirschenbaum Senior Yield Engineer Reflectivity, Inc. (408) 737-8100 x307 [EMAIL PROTECTED] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel