harrelfe / Hmisc

Harrell Miscellaneous
Other
208 stars 81 forks source link

`fit.mult.impute` fails with anonymous fitter function in R 4.2 #157

Closed krassowski closed 2 years ago

krassowski commented 2 years ago

This line:

https://github.com/harrelfe/Hmisc/blob/1b9c83e116dde149c72e443ad6065aa946547e14/R/fit.mult.impute.s#L9

Causes a failure with R 4.2 for custom anonymous fitter functions

Error in if (deparse(substitute(fitter)) == "lm") warning("If you use print, summary, or anova on the result, lm methods use the\nsum of squared residuals rather than the Rubin formula for computing\nresidual variance and standard errors.  It is suggested to use ols\ninstead of lm.") :
  the condition has length > 1

This is due to a significant change in R 4.2:

  • Calling if() or while() with a condition of length greater than one gives an error rather than a warning. Consequently, environment variable _R_CHECK_LENGTH_1CONDITION no longer has any effect.

An happens because anonymous functions get deparsed as demonstrated below

test = function(fitter) {
   print(deparse(substitute(fitter)))
}
# pass anonymous function
test(function(){NULL})

Prints three elements:

"function() {" "    NULL"     "}"
harrelfe commented 2 years ago

Thanks - fix will be in Hmisc 4.7-1