[R] [Questionnaire] Standardized Options: Justify/Alignment
|eo@m@d@ @end|ng |rom @yon|c@eu
Sun Sep 19 16:42:52 CEST 2021
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.
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",
3.) Standardized Names
justify = ... or align = ...?
pos = ... or position = ... or valign = ... ?
- "left", "right", "centre" vs "center"?
- using both "centre" and "center" break pmatch();
- "top", "bottom", "middle";
Native-English speakers should review this question as well.
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.
### Test Code
The latest version of the ftable2 function (contains a fix) and the
needed helper functions are available on Github:
### Some Data
mtcars$carbCtg = cut(mtcars$carb, c(1, 2, 4, +Inf), right=FALSE)
# 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",
More information about the R-help