rtables
rtables copied to clipboard
add type=width argument to nchar function
Issue originally reported by lil128 on Jul 24, 2020
this is not an issue, but a feature enhancement.
The root concern is related to China filing, where the health authority is requiring translation on everything. I just wonder if it could make sense that our reporting system supports these characters.
an example using refactored rtables can be
rtable(
header = c("测试\n测试2", "asda\nasdsa"),
rrow("行行行行行行行行行行", 1,2)
)
you can see that the layout is not correct. though using nchar(type="width") does not always solve the issue(depending on the font you choose: these characters does not always occupy twice the width of the alphabets)
Here's another example from lil128
library(rtables)
df <- data.frame(
a = sample(c('打算\ndasd', '的撒\ndasda\nasdas', '大苏打啊实打实的\n的撒大阿三大苏打'), replace = TRUE, size = 1000),
b = rnorm(1000)
)
basic_table() %>%
split_cols_by('a') %>%
analyze('b') %>%
build_table(df)
Result:
的撒
dasda 大苏打啊实打实的 打算
asdas 的撒大阿三大苏打 dasd
------------------------------
Mean -0.01 0.05 -0.1
So changing the type to width in what I believe are all the places it would need to be results in a different but still obviously wrong rendering of the table.
It is difficult to tell, but it looks like some of the chinese characters are taking up 2 positions while others are not:
(this is with experimental local changes to formatable):
> cat(toString(m, nch_type= "width"))
的撒
大苏打啊实打实的 dasda 打算
的撒大阿三大苏打 asdas dasd
——————————————————————————————————————
Mean 0.02 -0.01 0.05
> cat(toString(m, nch_type= "char"))
的撒
大苏打啊实打实的 dasda 打算
的撒大阿三大苏打 asdas dasd
——————————————————————————————
Mean 0.02 -0.01 0.05
Putting (keeping) a pin in this for now, but we'll leave it in the backlog