R语言officer包操作word存在的致命问题及解决方案

随着R语言的发展,它的社区也逐步扩展,现在R语言也越来越丰富了,不仅仅限于处理科学计算和数据可视化等它最擅长的领域,在一些你想不到的领域起始也可以小试牛刀,比如,操控office。

用解释性语言来操控office可以灵活地批量化处理一些文档事务,R语言自然也不能落后。R语言最常见的就是操作excel了,因为这个比较常用,这里就不再赘述。这里重点介绍说明一下R语言对word的操控。

1 存在的问题

一个比较不错的方案就是使用officer包。经过本人亲测,这个包在使用时存在一个致命问题,那就是非常重要的 body_replace_all_text 函数,通常达不到预期效果。当然,作者自己也在说明中提示了该风险:

Note that the behind-the-scenes representation of text in a Word document is frequently not what
you might expect! Sometimes a paragraph of text is broken up (or "chunked") into several "runs,"
as a result of style changes, pauses in text entry, later revisions and edits, etc. If you have not
styled the text, and have entered it in an "all-at-once" fashion, e.g. by pasting it or by outputing
it programmatically into your Word document, then this will likely not be a problem. If you are wo

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值