harrelfe / Hmisc

Harrell Miscellaneous
Other
205 stars 81 forks source link

latex.default exception with subscript out of bounds #116

Open simonsays1980 opened 5 years ago

simonsays1980 commented 5 years ago

Dear Frank,

first of all: thanks for providing your package to the community! Hmisc has spared me a lot of time transferring numbers out of R output into LateX tables.

Now to the issue: I am using Hmisc for a couple of years now and for a paper review I had to reproduce old Latex tables. I got surprised as the latex.default() method with longtable = TRUE and cgroups returned a subscript out of bounds exception. I debugged latex.default() and the error occurs in line 500 of latex.s:

rctcx <- cbind(rctcx, rcellTexCmds[, 1 + col.subs[[i]], drop=FALSE],
                       if(i < length(col.subs)) '')

This line occurs in a for loop that loops through the groups of cgroup (namely col.subs a list with vectors containing the column indices of each group):

for (i in seq(along=col.subs)) {
      cxi[[i]] <- cx[, col.subs[[i]], drop=FALSE]
      if(length(rctcx))
        rctcx <- cbind(rctcx, rcellTexCmds[, 1 + col.subs[[i]], drop=FALSE],
                       if(i < length(col.subs)) '')
    }

Now, as col.subs[[i]] necessarily has to be the collection of the last columns in the last iteration of this loop, the expression 1 + col.subs[[i]] must results in a column index that is out of bounds.

R version: 3.6.0 Hmisc : version with the error: 4.2-0 back to at least 4.0-3 OS : macOS 10.13.6 High SIerra

For me - as I needed a quick solution - rolling back my Hmisc installation towards version 3.17-0 ran like a charm. I post this here as an information such that others spare time when searching through this error.