[R] traceback and passing data frame

Daniel E. Ho daniel.ho at yale.edu
Thu Jul 7 04:31:12 CEST 2005


Hello,

Is there a way to suppress traceback() from returning the full structure of
a dataframe that is passed internally in a function?

As a simple toy example, suppose we had two functions that pass a dataframe
internally:

data(Formaldehyde)
fn2 <- function(formula, data, ...) {
  res <- lm(formula, data, subset="some error", ...)
}
fn1 <- function(formula,data,...){
  tmp <- do.call("fn2",list(formula,data,...))
}
foo <- fn1(carb~optden,data=Formaldehyde)

fn2() clearly contains an error in subset.  This example is just to
illustrate the issue with traceback(), so please ignore the fact that this
is just an lm() call.  traceback() returns the following information:

6: stop("0 (non-NA) cases")
5: lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...)
4: lm(formula, data, subset = "some error", ...)
3: fn2(carb ~ optden, structure(list(carb = c(0.1, 0.3, 0.5, 0.6,
   0.7, 0.9), optden = c(0.086, 0.269, 0.446, 0.538, 0.626, 0.782
   )), .Names = c("carb", "optden"), row.names = c("1", "2", "3",
   "4", "5", "6"), class = "data.frame"))
2: do.call("fn2", list(formula, data, ...))
1: fn1(carb ~ optden, data = Formaldehyde)

Is there a way for line 3 of the traceback output NOT to include all data
and attributes?

In my case this would be helpful because if the data frame is large it can
run off the terminal window, so it would make diagnostics easier with larger
datasets.

Many thanks for your time,

Dan
--------------
System Info:
platform x86_64-redhat-linux-gnu
arch     x86_64
os       linux-gnu
system   x86_64, linux-gnu
status
major    2
minor    1.1
year     2005
month    06
day      20
language R




More information about the R-help mailing list