nutterb / pixiedust

Tables So Beautifully Fine-Tuned You Will Believe It's Magic.
179 stars 18 forks source link

Numeric representation when `options()$scipen` has been changed #62

Closed nutterb closed 8 years ago

nutterb commented 8 years ago

In an e-mail from a user I received the following report

stuff <- results.print %>% dust %>% sprinkle_print_method("latex") %>% sprinkle(font_size=6) %>% print(asis = FALSE) %>% cat()

results.print <- results2[289:325, ] head(results.print) timestep walk-area date rain temp Ep Qt 289 289 BC 2013-10-16 2.85e-02 9.25e+00 8.58e-04 4.500e+02 290 290 BC 2013-10-17 1.05e-03 1.10e+01 9.44e-04 7.519e+03 291 291 BC 2013-10-18 3.33e-02 1.09e+01 9.23e-04 4.736e+04 292 292 BC 2013-10-19 2.38e-02 1.29e+01 1.03e-03 1.273e+06 293 293 BC 2013-10-20 1.59e-02 1.20e+01 9.58e-04 3.581e+02 294 294 BC 2013-10-21 1.87e-02 1.24e+01 9.74e-04 4.773e+03 qt qo qs qv Smean 289 2.583e-05 2.115e-05 4.682e-06 2.714e-02 3.606e-02 290 4.317e-04 6.860e-07 4.310e-04 1.934e-04 3.630e-02 291 2.719e-03 2.305e-03 4.143e-04 3.009e-02 6.618e-03 292 7.307e-02 1.479e-02 5.827e-02 8.069e-03 5.682e-02 293 2.056e-05 7.015e-06 1.354e-05 1.482e-02 4.201e-02 294 2.740e-04 1.143e-04 1.598e-04 1.767e-02 2.451e-02 > stuff <- results.print %>%

  • dust %>%
  • sprinkle_print_method("latex") %>%
  • sprinkle(font_size=6L) %>%
  • print(asis = FALSE) %>%
  • cat() \setlength{\tabcolsep}{6e+00pt} \begin{table} \centering

\label{tab:pixie-0e+00}\begin{tabular}{lllrrrrrrrrr} \multicolumn{1e+00}{l}{timestep} & \multicolumn{1e+00}{l}{walk-area} & \multicolumn{1e+00}{l}{date} & \multicolumn{1e+00}{r}{rain} & \multicolumn{1e+00}{r}{temp} & \multicolumn{1e+00}{r}{Ep} & \multicolumn{1e+00}{r}{Qt} & \multicolumn{1e+00}{r}{qt} & \multicolumn{1e+00}{r}{qo} & \multicolumn{1e+00}{r}{qs} & \multicolumn{1e+00}{r}{qv} & \multicolumn{1e+00}{r}{Smean} \

The following elements need to be guarded against scientific notation representations

Probably the easiest thing to do is store them in the internal structure as integers? Does that work for values that could theoretically accept a decimal?

nutterb commented 8 years ago

Under 0.7.4,

library(pixiedust)
DF <- 
structure(list(timestep = 289:294, walk.area = c("BC", "BC", 
"BC", "BC", "BC", "BC"), date = c("2013-10-16", "2013-10-17", 
"2013-10-18", "2013-10-19", "2013-10-20", "2013-10-21"), rain = c(2.85e-02, 
1.05e-03, 3.33e-02, 2.38e-02, 1.59e-02, 1.87e-02), temp = c(9.25e+00, 
1.1e+01, 1.09e+01, 1.29e+01, 1.2e+01, 1.24e+01), Ep = c(8.58e-04, 
9.44e-04, 9.23e-04, 1.03e-03, 9.58e-04, 9.74e-04), Qt = c(4.5e+02, 
7.519e+03, 4.736e+04, 1.273e+06, 3.581e+02, 4.773e+03), qt = c(2.583e-05, 
4.317e-04, 2.719e-03, 7.307e-02, 2.056e-05, 2.74e-04), qo = c(2.115e-05, 
6.86e-07, 2.305e-03, 1.479e-02, 7.015e-06, 1.143e-04), qs = c(4.682e-06, 
4.31e-04, 4.143e-04, 5.827e-02, 1.354e-05, 1.598e-04), qv = c(2.714e-02, 
1.934e-04, 3.009e-02, 8.069e-03, 1.482e-02, 1.767e-02), Smean = c(3.606e-02, 
3.63e-02, 6.618e-03, 5.682e-02, 4.201e-02, 2.451e-02)), .Names = c("timestep", 
"walk.area", "date", "rain", "temp", "Ep", "Qt", "qt", "qo", 
"qs", "qv", "Smean"), class = "data.frame", row.names = c(NA, 
-6L))

options(scipen = -10)

dust(DF) %>%
  sprinkle_print_method("html") %>%
  sprinkle(font_size=6) %>%
  sprinkle(cols = 1:2,
           rows = 1:2,
           merge_rowval = 2,
           merge_colval = 2,
           merge = TRUE)