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

as.character.formula breaks base R #11

Open
mayer79 opened this issue Dec 22, 2019 · 5 comments
Open

as.character.formula breaks base R #11

mayer79 opened this issue Dec 22, 2019 · 5 comments

Comments

@mayer79
Copy link

mayer79 commented Dec 22, 2019

Loading the package breaks R's behaviour of as.character.default, which is not too convenient.

as.character(.~.) # "~" "." "."
library(formula.tools)
as.character(.~.) # ". ~ ."

Do you see an easy way to avoid this?

@mayer79 mayer79 changed the title formula.tools:::as.character.formula as.character.formula breaks base R Dec 22, 2019
@Scott-Coggeshall
Copy link

Scott-Coggeshall commented Jun 29, 2021

I recently encountered this issue as well. Having formula.tools attached or loaded via a namespace breaks the oneway.test function from the base R stats package.

Example

# start with fresh R session in Rstudio

sessionInfo()

# R version 4.0.4 (2021-02-15)
# Platform: x86_64-w64-mingw32/x64 (64-bit)
# Running under: Windows Server x64 (build 14393)

# Matrix products: default

# locale:
# [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United # # # 
# States.1252 LC_NUMERIC=C                           LC_TIME=English_United States.1252    

# attached base packages:
# [1] stats     graphics  grDevices utils     datasets  methods   base     

# loaded via a namespace (and not attached):
# [1] compiler_4.0.4 tools_4.0.4    yaml_2.2.1  

# set up fake data for a simple one-way ANOVA

set.seed(23)


fake_data <- data.frame(x = rbinom(100, 1, .5), y = rnorm(100))




# running oneway.test, output is fine

oneway.test(y ~ x, data = fake_data)

# > oneway.test(y ~ x, data = fake_data)
#	One-way analysis of means (not assuming equal variances)
#
# data:  y and x
# F = 0.010084, num df = 1.000, denom df = 96.939, p-value = 0.9202
# > 

# attach formula.tools
library(formula.tools)

# re-run oneway.test

oneway.test(y ~ x, data = fake_data)

# running oneway.test now throws error
# > oneway.test(y ~ x, data = fake_data)
# Error in oneway.test(y ~ x, data = fake_data) : 
#  a two-sided formula is required
# > 

This occurs because oneway.test does some error-checking prior to running the ANOVA that relies on as.character returning a vector of length 3 when given a two-sided formula. Anything other than that and it throws an error.

@mayer79
Copy link
Author

mayer79 commented Mar 7, 2023

User contributed packages should not break base R. Any chance this could be fixed?

@mayer79
Copy link
Author

mayer79 commented Oct 27, 2023

Is this project dead?

@ctbrown
Copy link
Contributor

ctbrown commented Nov 2, 2023 via email

@mayer79
Copy link
Author

mayer79 commented Nov 3, 2023

This is a pity.

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

3 participants