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

Fix to_numeric() with inversed factor levels #469

Merged
merged 6 commits into from
Nov 27, 2023

Conversation

strengejacke
Copy link
Member

@strengejacke strengejacke commented Nov 27, 2023

Copy link

codecov bot commented Nov 27, 2023

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (2852033) 89.09% compared to head (e798cfb) 89.10%.

Files Patch % Lines
R/data_tabulate.R 54.54% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #469      +/-   ##
==========================================
+ Coverage   89.09%   89.10%   +0.01%     
==========================================
  Files          72       72              
  Lines        5409     5414       +5     
==========================================
+ Hits         4819     4824       +5     
  Misses        590      590              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@etiennebacher etiennebacher changed the title To_numeric_inverse_levels Fix to_numeric() with inversed factor levels Nov 27, 2023
Copy link
Member

@etiennebacher etiennebacher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@strengejacke
Copy link
Member Author

Once you change one or two files, there's a chain reaction of lintrs you have to fix ;-)
Waiting for checks to finish.

@strengejacke
Copy link
Member Author

Behaviour is now in line with table(as.numeric()):

library(datawizard)
f <- c(0, 0, 1, 1, 1, 0, 1)
x1 <- factor(f, levels = c(0, 1))
x2 <- factor(f, levels = c(1, 0))

table(as.numeric(x1))
#> 
#> 1 2 
#> 3 4
out <- to_numeric(x1, dummy_factors = FALSE, preserve_levels = FALSE)
table(out)
#> out
#> 1 2 
#> 3 4

table(as.numeric(x2))
#> 
#> 1 2 
#> 4 3
out <- to_numeric(x2, dummy_factors = FALSE, preserve_levels = FALSE)
table(out)
#> out
#> 1 2 
#> 4 3

Created on 2023-11-27 with reprex v2.0.2

@strengejacke strengejacke merged commit ec161a2 into main Nov 27, 2023
26 of 28 checks passed
@strengejacke strengejacke deleted the to_numeric_inverse_levels branch November 27, 2023 19:13
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

Successfully merging this pull request may close these issues.

2 participants