xrobin / pROC

Display and analyze ROC curves in R and S+
https://cran.r-project.org/web/packages/pROC/
GNU General Public License v3.0
118 stars 31 forks source link

Cannot create a roc curve with a formula and a with clause #111

Closed xrobin closed 1 year ago

xrobin commented 1 year ago

This is a follow-up of #101.

form <- as.formula("outcome ~ wfns")
with(df, roc(form))

Throws an error:

Erreur dans eval(substitute(expr), data, enclos = parent.frame()) : 
  argument 'envir' incorrect de type 'closure'
3: eval(substitute(expr), data, enclos = parent.frame())
2: with.default(df, roc(form))
1: with(df, roc(form))
xrobin commented 1 year ago

Note that this style also doesn't work with standard R functions such as glm:

form <- as.formula("outcome ~ wfns")
with(df, glm(form))

This is because it is the environment of the formula which matters. So that works instead:

form <- with(aSAH, as.formula("age ~ ndka"))
glm(form)

And it works as well with pROC currently:

form <-  with(aSAH, as.formula("outcome ~ wfns"))
roc(form)
xrobin commented 1 year ago

The solution is pretty ugly and may not be optimal, but the combination is now working and tested.

There will probably be edge cases where it doesn't work and the search should be loosened further. However it works in testthat tests.