-
Notifications
You must be signed in to change notification settings - Fork 89
Description
Hi,
I have a flextable object where the content of a few cells contain text like "XXX~{super YYY}", which should be interpreted like XXXYYY.
As far as I am aware, text within a flextable object is taken literally and there is no direct way to tell flextable to interpret it and make the conversion. Please correct me if I am wrong.
Therefore, I had to implement a function interpret_cell_content(s)
, which given a string s, returns the flextable code to do such conversion, for example:
interpret_cell_content("xxx~{super a}xxx~{sub b}xxx")
returns:
[1] "flextable::as_paragraph('xxx', flextable::as_sup('a'), 'xxx', flextable::as_sub('b'), 'xxx')"
and a second function interpret_all_cell_content(flx)
that:
- iterates through every cell in the flextable object flx
- calls function
code_snippet <- interpret_cell_content(cell_content)
to obtain flextable snippet - executes
flx <- flextable::compose(flx, ..., value = eval(parse(text = code_snippet)))
to overwrite the cell content
Of course, this is not ideal, as it requires potentially looping over all cells in the flextable, and I was wondering if there was a more straightforward approach to this.
Thank you in advance!