[R-pkg-devel] obscure syntax error

peter dalgaard pd@|gd @end|ng |rom gm@||@com
Fri Mar 22 11:42:41 CET 2019


It could use a little whitespace, but I (and the Rstudio script editor) can't spot anything wrong, like mismatching braces or parens, and all else-at-beginning-of-line is inside the function. 

Could it be an incomplete last line?

-pd

> On 22 Mar 2019, at 11:18 , Jim Lemon <drjimlemon using gmail.com> 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.
> 
> Jim
> 
> ______________________________________________
> R-package-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes using cbs.dk  Priv: PDalgd using gmail.com



More information about the R-package-devel mailing list