[R Code] Split long names in format.ftable
Dear List members, I have uploaded an improved version on Github. The function is now fully functional: - justify: left, right, cent...: TODO centre vs center; - sep: separator when printing; - pos: Top, Bottom; TODO: Middle; see: https://github.com/discoleo/R/blob/master/Stat/Tools.Data. I will address some open questions in a separate post. ### Test # Required: # - all functions from Github / section "Formatting": #?? from space.builder() to ftable2(); ### Data mtcars$carbCtg = cut(mtcars$carb, c(1, 2, 4, 8), right=FALSE) tbl = with(mtcars, table(cyl, hp, carbCtg, gear)) id = c(1,3,4); xnm = c("Long\nname: ", "", "Extremely\nlong\nname: ") xnm = paste0(xnm, names(dimnames(tbl))[id]); names(dimnames(tbl))[id] = xnm; ftbl = ftable(tbl, row.vars = id); ### FTABLE ftable2(ftbl, sep="|"); # works nicely ftable2(ftbl, sep=" ") ftable2(ftbl, sep=" | ") ftable2(ftbl, sep=" | ", justify="left") ftable2(ftbl, sep=" | ", justify="cent") # TODO: center vs centre ftable2(ftbl, sep=" | ", justify="left", justify.lvl="c") Sincerely, Leonard
On 9/15/2021 11:14 PM, Leonard Mada wrote:
Dear List members, I have uploaded an improved version on Github: - new option: align top vs bottom; Functions: split.names: splits and aligns the names; merge.align: aligns 2 string matrices; ftable2: enhanced version of format.ftable (proof of concept); see: https://github.com/discoleo/R/blob/master/Stat/Tools.Data.R It makes sense to have such functionality in base R as well: it may be useful in various locations to format character output. Sincerely, Leonard On 9/14/2021 8:18 PM, Leonard Mada wrote:
Dear List members, I wrote some code to split long names in format.ftable. I hope it will be useful to others as well. Ideally, this code should be implemented natively in R. I will provide in the 2nd part of the mail a concept how to actually implement the code in R. This may be interesting to R-devel as well. [...] C.) split.names Function This function may be useful in other locations as well, particularly to split names/labels used in axes and legends in various plots. But I do not have much knowledge of the graphics engine in R. Sincerely, Leonard