Leonard Mada
2021-Sep-19 14:42 UTC
[R] [Questionnaire] Standardized Options: Justify/Alignment
Dear R users, I have started to work on an improved version of the format.ftable function. The code and ideas should be reused to improve other R functions (enabling more advanced format of the character output). However, there are a number of open questions. These are focused on standardizing the names and the options of the various arguments used to format the output. A separate post will address questions related to technical and design decisions. Note: The arguments are passed to various helper functions. It may be tedious to modify once implemented. Furthermore, package developers should be encouraged to use the standardized names and options as well (and may use the helper functions as well). The users are also encouraged to test the various options. Some code to enable testing is available at the end of this post. Structure of "Questionnaire": a.) Answers should follow a Likert-type scale: # Strongly disagree (on option ...); # Disagree (on option ...); # Agree (on option ...); # Strongly agree (on option ...); b.) Motivation: ... c.) Other comments: ... ### The "Questionnaire" 1.) "MiddleTop", "MiddleBottom" vs "Middle" Example problem: positioning 3 lines of text on 4 rows; Workaround: user can easily prepend or append a newline to the relevant names, forcing the desired behaviour. However, there is a helper function to merge (cbind) 2 string matrices and it may be tedious for a user to modify all names. [but this is less used in ftable] Disadvantages: the 2 variants "break" pmatch()! 2.) Lower case vs Upper case Motivation: the options for most named algorithms are uppercase and are likely to remain uppercase; Example: option = c("MyName1", "MyName2", "Fields1", "Fields2", ...); Existing options in format.ftable: are lowercase, "left", "right", *"centre"*; 3.) Standardized Names 3.a.) Arguments: justify = ... or align = ...? pos = ... or position = ... or valign = ... ? 3.b.) Options: - "left", "right", "centre" vs "center"? - using both "centre" and "center" break pmatch(); - "top", "bottom", "middle"; Native-English speakers should review this question as well. Note: The new function enables to justify differently both the row-names and the factor levels: - there are actually 2 arguments: justify="left", justify.lvl="c"; # with centre vs center issue! I do not now if there is any facility to run such questionnaires through R. My resources are also rather limited - if anyone is willing to provide help - I would be very happy. Sincerely, Leonard ========== ### Test Code The latest version of the ftable2 function (contains a fix) and the needed helper functions are available on Github: https://github.com/discoleo/R/blob/master/Stat/Tools.Data.R ### Some Data mtcars$carbCtg = cut(mtcars$carb, c(1, 2, 4, +Inf), right=FALSE) # Alternative: # mtcars$carbCtg = cut(mtcars$carb, c(1, 2, 4, 8), include.lowest=TRUE) tbl = with(mtcars, table(cyl, hp, carbCtg, gear)) id = c(1,3,4); # Note: the names can be modified to test various scenarios 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) ### Test: FTABLE ftable2(ftbl, sep=" | ", justify="left", justify.lvl="c", pos="Top", split="\n")