[R] infinite recursion problem

Mathieu Ros mathieuros at bigfoot.com
Thu Mar 9 17:53:18 CET 2000


Thomas Lumley wrote :

> On Wed, 8 Mar 2000, Mathieu Ros wrote:
>
> > hello r-users,
> > sorry for asking a long question that may not be very relevant for the
> > list but it's upsetting me and I get no other solution...
>
> We need the example to tell what's wrong -- ie we need HTMLExport as well
> as HTMLExport.list.
>
> Based on just this function I can't see why there is a problem or why the
> change that you say helps in S-PLUS would do anything.
>
> The question about S-PLUS would be more appropriate for the s-news mailing
> list, but if the function called by .C was undocumented in Splus4 it's
> quite possible that it doesn't exist in Splus5.
>
> Thomas Lumley
> Assistant Professor, Biostatistics
> University of Washington, Seattle
>

Thanks for your reply and sorry for my uncomplete posting of yesterday (it
was late...). Original posting is enclosed below.
any hints would be very appreciated.

here are HTMLExport (generic function) and HTMLExport.lm :

"HTMLExport"<-
function(x, ...)
{
 UseMethod("HTMLExport")
}

"HTMLExport.lm"<-
function(lmobject, File = "", Directory = "./", Desc = F, ...)
{
 options(warn = -1)
 GraphDirectory <- Directory
 NameReg <- deparse(substitute(lmobject))
 if(File == "") {
  File <- paste(Directory, "Result.of.regression.", NameReg,
   ".html", sep = "")
 }
 txt <- lmobject$model
 # txt <- substring(txt, regexpr("data=*", txt) + 5, nchar(txt) - 1)
 donnees<-txt
 eval(parse(text = "attach(donnees, pos=2)"))
 # File <- HTMLInitFile(File)
 vardep <- as.character(attr(lmobject$terms, "variables"))[-1]
 variables <- attr(lmobject$terms, "term.labels") #
 HTMLTitle("&nbsp;<B>Results of regression</B>", Size = "+3", BackColor
   = "000000", Color = "FFFFFF", File = File) #
#
# GENERATION DE L'INDEX
 ...<deleted>...
 if(Desc == T) {
  HTMLExport(as.title("Descriptive informations"), File = File)
  HTML.LI(paste("Data for regression: ",deparse(substitute(lmobject)), sep =
""), File =
   File)
  HTML.LI(paste("Dimensions of the data: ", dim(donnees)[1],
   " X ", dim(donnees)[2], sep = ""), File = File)
  HTML.LI(paste("Dependant variable: ", vardep, sep = ""), File
    = File)
  HTML.LI("List of variables: ", File = File)
  cat(variables, sep = "&nbsp; | &nbsp;", append = T, file = File
   )
  HTML.BR(File = File)
  HTML.LI("<B><A NAME=#desc-correlations>Correlation matrix</A></B>: ",
   File = File)
  data <- donnees[, c(vardep, variables)]
  HTMLExport(round(cor(data), 4), FirstColumnBold = T,
   FirstRowBold = T, File = File)
  desc <- t(t(summary(data[, vardep])))
  if(dim(desc)[1] == 6) {
   desc <- rbind(desc, 0)
  }
  for(var in variables) {
   desc2 <- t(t(summary(data[, var])))
   if(dim(desc2)[1] == 6) {
    desc2 <- rbind(desc2, 0)
   }
   desc <- cbind(desc, desc2)
  }
  dimnames(desc) <- list(c("Min.", "1st Qu.", "Median", "Mean",
   "3rd Qu.", "Max.", "NA"), c(vardep, variables))
  HTML.LI("<A NAME=#desc_stats><B>Descriptive statistics</B></A>: ",
   File = File)
  HTMLExport(round(desc, 4), FirstColumnBold = T, File = File)
  HTML.LI("<A NAME=#desc_boxplots><B>Boxplots:</B></A>", File =
   File)
  AllVar <- c(vardep, variables)
  k <- trunc((length(AllVar) - 1)/4)
  par(mfrow = c(1, 4))
  for(i in 0:k) {
   subvar <- AllVar[(4 * i + 1):(4 * i + 4)]
 #  print(subvar)
   for(var in subvar) {
    if(var != "") {
      boxplot(data[, var], outchar = T, main = var)
    }
   }
   HTMLInsertGraph(File = File, GraphDirectory =
    GraphDirectory, GraphFileName = paste("boxplot",
    i + 1, ".", NameReg, sep = ""))
  }
 }
 HTMLTitle(as.title("Summary"), File = File)
 HTMLExport(summary(lmobject), File = File)
 HTMLTitle(as.title("Graphs"), File = File)
 HTMLPlot.lm(lmobject, GraphDirectory = GraphDirectory, Name = NameReg,
  File = File)
 HTMLEndFile(File)
 detach(what = 2)
 options(warn = 1)
}


>
> >
> > I get a function HTMLExport.lm that uses another function called
> > HTMLExport.list.
> > My problem is that function HTMLExport.list works fine when used alone
> > but HTMLExport.lm crashes with the following error :
> >
> > > HTMLExport(iris.lm)
> > lm(formula = Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width)
> > Error in names.default(x) : evaluation is nested too deeply: infinite
> > recursion?
> >
> > Here is the code of HTMLExport.list :
> > "HTMLExport.list"<-
> > function(x, prefix = "", File = "", Align = "left", ...)
> > {
> >  xlen <- length(x)
> >  if(xlen == 0) {
> >   cat("list()\n")
> >   return(invisible(x))
> >  }
> >  n <- names(x)
> >  if(is.null(n))
> >   this <- paste(prefix, "[[", 1:xlen, "]]", sep = "")
> >  else this <- paste(prefix, "$",names(x), sep = "")
> >  for(i in 1:xlen) {
> >   this[i] <- substring(this[i], 2, nchar(this[i]))
> >   cat(paste("<P ALIGN=", Align,
> >    "><TABLE BORDER=0><TD BGCOLOR=E4E4E4><FONT FACE=ARIAL><B>",
> >    this[i], "</TD></TABLE></P>", sep = ""), file = File,
> >    append = T, sep = "")
> >   HTMLExport(x[[i]], File = File, prefix = this[i], ...)#here is the
> > problem according to debug()
> >  }
> >  invisible(x)
> > }
> >
> >
> > In Splus4 version of these function, the problem had been fixed using
> > this <- paste(prefix, "$", .C("names_unlex",n,as.integer(xlen))[[1]],
> > sep = "")
> > instead of
> > this <- paste(prefix, "$",names(x), sep = "")
> > but it can't work within R...
> >
> > Could someone explain me what happens (even if I have a vague idea)
> > and/or give me a tip to handle this problem.
> >
> > Also, I get Splus5.1 (linux mandrake7.0) and can't find a way to use
> > .C("names_unlex",...), could someone explain me what it does and where
> > to find the code (if it's not a Splus4 feature?).
> >
> > thanks a lot,
> >     Mathieu

--
----------------------------------------------------------------------
Mathieu Ros - 13 rue bévière - 38000 GRENOBLE - 04 76 491 370
http://mathieu.ros.free.fr/
DESS ingénierie mathématique (biostatistiques)
Universite Joseph Fourier, Grenoble
----------------------------------------------------------------------
l'expérience est le nom que chacun donne a ses erreurs. Wilde



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list