harrelfe / Hmisc

Harrell Miscellaneous
Other
208 stars 81 forks source link

Problem with latex.summaryM.formula() resetting the global digits option #65

Closed ruddjm closed 6 years ago

ruddjm commented 7 years ago

When including 2 variables on the right hand side of the formula argument, providing a digits argument can change the global digits option.

Here is an example:

set.seed(173) country <- factor(sample(c('US', 'Canada'), 500, rep=TRUE)) age <- rnorm(500, 50, 5) treatment <- factor(sample(c("Drug","Placebo"), 500, rep=TRUE))

options(digits = 3) latex( summaryM(age ~ treatment + country), digits = 1, file = "") options('digits')

This is happening with or without providing a group argument.

harrelfe commented 7 years ago

The only place where digits is referenced in latex.summaryM has this:

   if(!missing(digits)) {
      oldopt <- options(digits=digits)
      on.exit(options(oldopt))
    }

So I need help figuring out how that could not do the job.

couthcommander commented 7 years ago

I think you want this instead:

oldopt <- options('digits')
options(digits = digits)
on.exit(options(oldopt))
harrelfe commented 6 years ago

Sorry for not responding sooner. That fix was made a while ago but can't remember if it's on CRAN. It will definitely be in the new version to be submitted to CRAN within 2 days.