nutterb / pixiedust

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

Addition to Manual #75

Open ckraner opened 7 years ago

ckraner commented 7 years ago

While working with the LaTeX output, I faced a lot of errors. This turned out to be due to my item names including a title like df$branch so the $ started an equation. It's my fault, not the codes, but this should be noted in the manual and guide.

nutterb commented 7 years ago

You are correct that this could be better described. I'll work this into the documentation.

When you first got all of those errors, where was the first place you wanted to look for a solution? (asking so I can target the most effective place to put these details)

ckraner commented 7 years ago

So sanitize fixed all the errors this caused, as I mentioned in the other issue. However, this is in none of the documentation or examples. My order of reference use was:

  1. The instructional page on CRAN - Here
  2. The package documentation
ckraner commented 7 years ago

So after working with this and your help, I was able to create a table very similar to your example in the guide, with the addition of rules between columns. The LaTeX output does not automatically add the horizontal lines you imply in the guide. Here is my code, using the mtcars fit you did in the example, all the additional coding is from sprinkle(sanitize=TRUE)%>% on:

#This gives you the number of the last row to place the trailing line
nvar=length(fit$coefficients)

options(pixiedust_print_method = "latex")
dust(fit, float=FALSE, hhline=TRUE) %>%
  sprinkle(cols = "term", 
      replace = c("Intercept", "Quarter Mile Time", "Automatic vs. Manual",
                  "Weight", "Gears: 4 vs. 3", "Gears: 5 vs 3")) %>%
  sprinkle_colnames(term = "Term", p.value = "P-value", 
                    std.error = "SE", statistic = "T-statistic",
                    estimate = "Coefficient")%>%
  sprinkle(cols=c("estimate","std.error","statistic"),round=2) %>%
  sprinkle(cols="p.value", fn = quote(pvalString(value))) %>%
  sprinkle(sanitize = TRUE) %>%
  sprinkle(cols = c(2,4), halign = "center", border = c("left","right"), border_thickness = .5)%>%
  sprinkle(cols = 3, halign = "center") %>%
  sprinkle(rows = nvar, border = "bottom", border_thickness = .5)%>%
  sprinkle(rows = 1, sanitize = TRUE, border = c("top","bottom"), border_thickness = .5, part = "head")

hhline being TRUE or FALSE doesn't change anything. Note: I had to use results='asis' in knitr. When I used results='tex' I get the output, but it is gray instead of black.

I hope this will help when crafting your new guide! This is a very useful package. Next I will be working on adding captions and labels, but this looks very straightforward.