ProjectMOSAIC / ggformula

Provides a formula interface to 'ggplot2' graphics.
Other
39 stars 11 forks source link

Bug: on-the-fly computation in df_stats() fails #78

Closed rpruim closed 6 years ago

rpruim commented 6 years ago
df_stats( ~(length / width), data = KidsFeet)
##    width  min     Q1 median     Q3  max     mean        sd n missing
## 1    7.9 21.6 22.125  22.65 23.175 23.7 22.65000 1.4849242 2       0
## 2    8.1 24.2 24.200  24.20 24.200 24.2 24.20000        NA 1       0
## 3    8.3 24.0 24.000  24.00 24.000 24.0 24.00000        NA 1       0
## 4    8.4 24.4 24.400  24.40 24.400 24.4 24.40000        NA 1       0
## 5    8.5 22.9 22.900  22.90 22.900 22.9 22.90000        NA 1       0
## 6    8.6 22.5 23.925  24.45 24.550 24.7 24.02500 1.0242884 4       0
## 7    8.7 24.0 24.000  24.00 24.000 24.0 24.00000        NA 1       0
## 8    8.8 22.9 23.000  24.60 24.700 25.4 24.12000 1.1122050 5       0
## 9    8.9 24.2 24.500  24.80 24.950 25.1 24.70000 0.4582576 3       0
## 10   9.0 23.6 24.275  25.25 26.175 26.7 25.20000 1.4071247 4       0
## 11   9.1 26.1 26.100  26.10 26.100 26.1 26.10000        NA 1       0
## 12   9.2 24.0 24.000  24.00 24.000 24.0 24.00000        NA 1       0
## 13   9.3 23.6 23.825  23.95 24.500 26.0 24.37500 1.0965856 4       0
## 14   9.4 27.1 27.100  27.10 27.100 27.1 27.10000        NA 1       0
## 15   9.5 25.5 25.500  25.50 25.800 26.1 25.70000 0.3464102 3       0
## 16   9.6 26.1 26.100  26.10 26.100 26.1 26.10000        NA 1       0
## 17   9.7 24.5 24.800  25.10 25.400 25.7 25.10000 0.8485281 2       0
## 18   9.8 25.2 26.100  27.00 27.250 27.5 26.56667 1.2096832 3       0
favstats( ~ (length / width), data = KidsFeet)
##       min       Q1   median       Q3 max     mean        sd  n missing
##  2.525773 2.635853 2.755102 2.858485   3 2.752867 0.1293831 39       0
rpruim commented 6 years ago

Note: This does work. This goes back to our use of model.frame()

df_stats( ~I(length / width), data = KidsFeet)
##        min       Q1   median       Q3 max     mean        sd  n missing
## 1 2.525773 2.635853 2.755102 2.858485   3 2.752867 0.1293831 39       0
rpruim commented 6 years ago

This also works because left and right sides of formula are treated differently.

df_stats( length / width ~ 1, data = KidsFeet)
##        min       Q1   median       Q3 max     mean        sd  n missing
## 1 2.525773 2.635853 2.755102 2.858485   3 2.752867 0.1293831 39       0
rpruim commented 6 years ago

By pre-processing the formula, we can get some arithmetic operations (/, *, ^) that are handled specially by model.frame() to be treated like regular arithmetic. Parens force evaluation as well.

df_stats( ~ (length / width), data = KidsFeet)
##        min       Q1   median       Q3 max     mean        sd  n missing
## 1 2.525773 2.635853 2.755102 2.858485   3 2.752867 0.1293831 39       0

df_stats( ~ length / width, data = KidsFeet)
##        min       Q1   median       Q3 max     mean        sd  n missing
## 1 2.525773 2.635853 2.755102 2.858485   3 2.752867 0.1293831 39       0

df_stats( ~ (length + width), data = KidsFeet)
##    min    Q1 median Q3  max     mean       sd  n missing
## 1 29.5 32.75   33.4 35 37.3 33.71538 1.690148 39       0
rpruim commented 6 years ago

Closing this here. Will be fixed in mosaicCore.