R6 within S3 confusion #413
dheimgartner
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
I agree this is not convenient. This is something that could/should be improved. But I think everything should ideally use the But for now, it's not really possible to clone/copy an 'officer' object. Feel free to propose a PR to clone an object, but I think it's not a clear part in the code (undocumented R6), and it could be difficult :/ I can add a TODO for that feature, but I can't promise I will dedicate time to this soon (sorry again...). |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
Thanks so much for this great package!
I would like to elaborate on one point that I find a little confusing and its consequence:
The confusion arises because of the following implementation:
officer::read_docx()
is of classS3
S3
object lives a field that isR6
(namely thex$doc_obj
)Many of your functions directly act on this field (e.g. the
officer::body_replace_all_text
which thus directly modify the main object (reference semantics).Here a simple example where
template
points to some local.docx
file with the text replace_this appearing somewhere:I am not that knowledgeable in OO but I don't expect
S3
to have reference semantics. Maybe I am wrong in this point and one should expect this behaviour. Nevertheless, one thing that I find unlucky is that there is no obvious way to not change the original document. I.e.changes
replace_this
even intest_copy
.(My idea was to iterate over a
.docx
letter template and substitute addresses, names, etc.)One solution would be to change the main object (in the above example the
rdocx
) to anR6
. Then one could use thex$clone()
to initialize a clone and modify the clone without sideeffects...Would be happy to hear your thoughts!
Best,
Daniel
Beta Was this translation helpful? Give feedback.
All reactions