On 22/03/19 11:18 PM, Jim Lemon wrote:

Hi,
I have been attempting to check a new version of the prettyR package,
and have struck a difficult problem. The check fails at the
installation, and when I track the error, it is "Unexpected end of
input" in the xtab function. I have tried a number of things as I
thought that it was a non-printing character (I have had that happen
before). I can paste the entire function into an R session and there
is no error. Has anyone struck an error like this before?

xtab<-function(formula,data,varnames=NULL,or=TRUE,chisq=FALSE,phi=FALSE,
  html=FALSE,bgcol="lightgray") {

  if(missing(formula))
   stop("Usage: 
xtab(formula,data,varnames=NULL,or=TRUE,chisq=FALSE,phi=FALSE\n")
  ft<-as.character(attr(terms(formula),"variables")[-1])
  nft<-length(ft)
  if(nft>2) {
   xt<-list()
   by.factor<-as.factor(data[[ft[nft]]])
   factor.levels<-levels(by.factor)
   factor.labels<-attr(data[,ft[nft]],"value.labels")
   if(!is.null(names(factor.labels))) factor.labels<-names(factor.levels)
   if(is.null(factor.labels)) factor.labels<-factor.levels
   nlevels<-length(factor.levels)
   for(i in 1:nlevels) {
    currentdata<-subset(data,by.factor==factor.levels[i])
    for(j in 1:dim(currentdata)[2])
     attr(currentdata[,j],"value.labels")<-attr(data[,j],"value.labels")
    currentcount<-length(currentdata[[nft]])
    totalcount<-length(data[[nft]])
    cat("\nCount for",ft[nft],"=",factor.labels[i],"is",currentcount,
     "(",round(100*currentcount/totalcount,1),"%)\n\n")
    rightside<-ifelse(nft>3,paste(ft[2:(nft-1)],sep="",collapse="+"),ft[2])
    next.formula<-as.formula(paste(ft[1],rightside,sep="-",collapse=""))
    xt[[i]]<-xtab(next.formula,data=currentdata,varnames=varnames,chisq=chisq,
     phi=phi,html=html,bgcol=bgcol)
   }
  }
  else {
   if(missing(data)) xt<-calculate.xtab(get(ft[1]),get(ft[2]),varnames=varnames)
   else xt<-calculate.xtab(data[,ft[1]],data[,ft[2]],varnames=varnames)
  }
  attr(xt,"class")<-"xtab"
  return(xt)
}
  Thanks for any pointers.

I believe I have encountered phenomena like this where the error was actually in the *"previous"* function in the sequence of package functions stored in the *.rdb or *.rdx files in the "R" directory of the package.

To track down where the error is actually occurring I cd to the R
directory of the *source* package, start R, and do something like:

phials <- list.files(pattern=".R$")
for(phial in phials) {
    cat(phial,"\n")
    source(phial)
}

That should allow you to spot the loony pretty quickly.

HTH

cheers,

Rolf

--
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

______________________________________________
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel

Reply via email to