Skip to content
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

Closed
hemonika opened this issue Nov 10, 2022 · 3 comments

Comments

@hemonika
Copy link

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.

@gregorsteiner
Copy link
Collaborator

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).

@hemonika
Copy link
Author

hemonika commented Nov 16, 2022 via email

@gregorsteiner
Copy link
Collaborator

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,
Gregor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants