-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
oneway.test function from stats package gives error when used after logistf is loaded #49
Comments
Hi, the problem is that logistf imports the formula.tools package, which introduces a formula method for as.character(). When formula.tools is loaded, length(as.character()) applied to a formula object returns 1 instead of 3. One way to avoid this is to explicitly use the default method. That is: formula <- extra ~ group
length(as.character(formula))
# returns 1
length(as.character.default(formula))
# returns 3 You could modify the oneway.test() function by explicitly using the default method (as above) in the if statement. This modified version should work even if logistf is loaded (it does on my machine running R version 4.2.0). |
Dear Gregor
Thank you very much for your reply.
You explain where this problem comes from, very good.
And you suggest that I modify the base R oneway.test function in order to make logistf work together with it.
Yes, this is a valid workaroaund, but I think this is not the best possible solution to this problem. In my opinion one should never have to modify by hand a base R function to work properly again because another package destroys its functionality.
When I look at the formula.tools package I see that it was never updated since March 2018, so almost 5 years.
So I think your package should not rely on such an old package, that in addition destroys base R functions unknowingly.
So maybe you could work on this?
Kind regards
Monika
Gesendet: Mittwoch, 16. November 2022 um 09:01 Uhr
Von: "Gregor Steiner" ***@***.***>
An: "georgheinze/logistf" ***@***.***>
Cc: "hemonika" ***@***.***>, "Author" ***@***.***>
Betreff: Re: [georgheinze/logistf] oneway.test function from stats package gives error when used after logistf is loaded (Issue #49)
Hi, the problem is that logistf imports the formula.tools package, which introduces a formula method for as.character(). When formula.tools is loaded, length(as.character()) applied to a formula object returns 1 instead of 3. One way to avoid this is to explicitly use the default method. That is:
formula <- extra ~ group
length(as.character(formula))
# returns 1
length(as.character.default(formula))
# returns 3
You could modify the oneway.test() function by explicitly using the default method (as above) in the if statement. This modified version should work even if logistf is loaded (it does on my machine running R version 4.2.0).
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Dear Monika, I agree that this is not the best possible solution. We will work on it, but unfortunately I cannot promise that we will be able to drop the formula.tools dependency in the near future. Best, |
Examples of oneway.test function throw errors after loading logistf:
library(logistf)
oneway.test(extra ~ group, data = sleep)
gives the following error:
Error in oneway.test(extra ~ group, data = sleep) :
a two-sided formula is required
This can be pinned down to
if (length(as.character(formula)) != 3L)
stop("a two-sided formula is required")
it seems that with logistf the formula interface is changed in a way that when applying the as.character function on formulas, they give back the value 1 instead of 3 which is the default.
I could reproduce this error in R versions 4.2.2 and 4.1.3.
The text was updated successfully, but these errors were encountered: