RMarkdown 包 flextable 立即失败,并显示“read_docx only support docx"; [英] RMarkdown package flextable fails immediately with "read_docx only support docx"

查看:38
本文介绍了RMarkdown 包 flextable 立即失败,并显示“read_docx only support docx";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于一个最少产生的问题,我很抱歉......没有很多信息,因为它在我第一次尝试时失败了,而且我在 RMarkdown 调试方面还不是很熟练.

I'm sorry for a minimally produced question...... not lots of information because it just fails the first time I'm ever trying with this and I am not very skilled in RMarkdown debugging yet.

我第一次尝试使用 flextable(对控制 HTML 和 Word 中的表格输出感兴趣).

I'm trying flextable for the first time (interested in controlling table output in both HTML and Word).

已安装 Flextable 并为 HTML 运行,但根本停止对 Word 的任何渲染.当我尝试编织到 Word 时,在我得到一个新的 Word 文件之前,它停止并在 RMarkdown 面板中出现错误,是:

Flextable installed and it runs for HTML, but stops any rendering to Word at all. When I try to knit to Word, before I get a new Word file at all, it stops with an error in the RMarkdown panel, being:

Line [first line of R-chunk]: Error: read_docx only support docx files Execution halted  

有没有人见过并解决过这个问题?只有一个可能与此相关的问题在这里,但还没有答案:(

Has anyone seen and solved this before? There is just one SO question potentially related to this here , but no answers yet :(

编辑——我发现了一些东西,但这仍然是一个问题:-p
我又想到了一件事,那就是定制"....我已经有了自己的reference_docx.
当我把它拿走以便使用默认的 Word 模板时......它运行了!!
但我绝对想要我的风格!!flextable 不是我唯一可以使用的东西 :-D.
有谁知道对 flextable 的 reference_docx 有任何限制吗?
或者我们可能会猜测这些限制实际上是针对军官的?
他们能克服吗?

EDIT -- I found something, but that's still a problem :-p
I thought of one more thing that is "custom" ... I already have my own reference_docx .
When I took that away so that the default Word template is used... it runs!!
But I definitely want my styles !! flextable is not the only thing that I can possibly use :-D.
Does anyone know about any restrictions on the reference_docx for flextable?
Or might we guess the restrictions are actually for officer ?
Can they be overcome?

我不会费心转储标题,因为无论如何你都没有我的文件.但肯定它是 Word 的最新格式,因为我有 Office 365,如果我想的话,几乎无法停止 Windows 更新.
我将尝试自己解压缩 docx,并检查 docx 的元数据与使用默认值的 Knit 中看到的标准元数据是否有任何差异.

I won't bother dumping the headers because you don't have my file anyways. But certainly it's the newest format of Word as I have Office 365 and can't hardly stop Windows Updates if I want to.
I'll try to unpack the docx myself and check out if there's any differences in the metadata of the docx and the standard one as seen in a Knit using the default.

EDIT/UPDATE 2 -- 无法破解文件,而且..... 可能无关紧要所以我确实通过了 zip 转换,使我首选的 reference_docx 成为一个文件夹,并且使用默认"制作的输出 docx 是一个文件夹.到一个文件夹中.我查看了 BeyondCompare,也许最大的区别是我喜欢的尾注中有尾注信息.
我用的是Zotero,所以我实际上从Word中卸载了Zotero,重新保存,没有任何变化.
我尝试从文档中删除所有尾注并重新保存并没有更改.
我尝试编辑原始文件夹以删除endnotes.xml";文件,重新压缩它,尝试在 Word 中打开,让它修复,重新保存...没有变化.
我尝试另外删除与尾注"相关的顶级 xml 中的条目.并且还重新压缩并打开并修复并重新保存.....没有变化.

EDIT/UPDATE 2 -- failed to hack file, and..... maybe doesn't matter So I did go through the zip transformation to make my preferred reference_docx a folder and the output docx made with "default" into a folder. I checked with beyondCompare and perhaps the biggest difference is that there is information for endnotes in my preferred one.
I use Zotero, so I actually uninstalled Zotero from Word, resaved, and no change.
I tried removing all the endnotes from the document and resaved and no change.
I tried editing the raw folder to remove an "endnotes.xml" file, re-zipped it, tried to open in Word, let it repair, resaved . . . no change.
I tried additionally removing an entry in a top-level xml related to "endnotes" and also rezipped and opened and repaired and resaved ..... no change.

所以我接受了也许我只需要重建我喜欢的参考文档样式,并尝试使用 pandocdefault"的输出 docx重新开始.我确实认为首先将其用作 reference_docx 以确保它有效......
它不是 .:(

So I accepted that maybe I just have to rebuild my preferred reference doc styles, and tried to use the output docx from pandoc "default" to start over. And I did think to just use that as the reference_docx first just to make sure it works . . . . . .
it does not . :(

  • 所以我们可以看到我的盒子上有一些关于 docx 文件的东西freetable 或官员根本不会接受参考文档.

我可能不得不向他们提出.
同时,我可以查看是否有用于默认"的实际文档文件.也许那时我仍然可以继续工作.

I'll probably have to raise it with them.
In the meantime, I can see if there's an actual doc file used for "default" and maybe then I can still get things going.

我在 Windows 10 上运行 RStudio 1.3.1073.
我正在运行的简单代码是:

I'm running RStudio 1.3.1073 on Windows 10.
The simple code I'm running is:

``` {r}

library(dplyr)
library(flextable)

myDF = mtcars 


myDF[1:10,] %>%
      flextable()


```

运行 sessionInfo() 产生:

running sessionInfo() yields:

R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] rstudioapi_0.11  knitr_1.29       magrittr_1.5     tidyselect_1.1.0 munsell_0.5.0    colorspace_1.4-1 R6_2.4.1         rlang_0.4.7     
 [9] dplyr_1.0.2      tools_4.0.2      grid_4.0.2       gtable_0.3.0     xfun_0.16        tinytex_0.25     htmltools_0.5.0  ellipsis_0.3.1  
[17] yaml_2.2.1       digest_0.6.25    tibble_3.0.3     lifecycle_0.2.0  crayon_1.3.4     purrr_0.3.4      ggplot2_3.3.2    vctrs_0.3.2     
[25] glue_1.4.1       evaluate_0.14    rmarkdown_2.3    compiler_4.0.2   pillar_1.4.6     generics_0.0.2   scales_1.1.1     pkgconfig_2.0.3 
> 


只是为了确认~~~只是为了清楚我已经将它隔离为使用 flextable() - 或者可能是 magrittr,但这似乎不太相关 - 这很好:


just to confirm ~~~ just to be clear that I have already isolated it to using flextable() - or potentially magrittr, but that seems less related - this is fine:

``` {r }


library(dplyr)
library(flextable)


myDF = datasets::mtcars 


myDF[1:10,] 
  # %>%
  #     flextable()


```  

我已经使用 RMarkdown 几个星期了,之前生成过 docx.
如果我不使用 flextable,我仍然可以生成 docx,包括这个最小的数据转储,只选择上面没有 flextable 的 10 行.
当我合并 flextable 时,我们遇到了一个奇怪的问题.

I have been using RMarkdown for a couple weeks and generating docx previously.
I can still generate docx if I don't use flextable, including this minimal data dump with just selecting 10 rows as above without flextable.
When I incorporate flextable we have a strange problem.

并且只是为了额外,更加清晰,取出magrittr我仍然得到相同的行为...... HTML没问题,Word得到如下错误:

And just to be extra, extra clear , taking out magrittr I still get the same behavior ... HTML is ok, Word gets error as stated:

``` {r }


library(dplyr)
library(flextable)


myDF = datasets::mtcars 


flextable(myDF[1:10,])


  # %>%
  #     flextable()


```

回答另一个问题,
是的,我已经尝试更新所有软件包并检查 RStudio 更新

推荐答案

omg -- 这是因为我的 reference_docx 的文件路径有空格(可能还有其他字符)

我还没有检查其他特殊字符,所以可能还有其他字符,但肯定空间足以打破它.

I didn't check for other special characters yet, so may be other characters, but for sure space is enough to break it.

我的原始文件路径是(部分编辑了相同长度的字母和数字项目)

My original file path was (partially redacted with same length items for letters and numbers)

C:\Zzzzz\yyyy\XxxXxxxx\--------1111,1111 aaaaaaa bbbb cccc\ddd e.f. !\_-_ ggggg hhhhh iiii jjjjjjj kkkkk\R source\_outputTemplates\  

我试着让它变得非常简短,也很简单,看看这是否是偶然的问题,因为我还没有尝试过,我一直在想……我们知道这是一个本地问题,所以它一定是这样的.

I tried making it really short and also simple to see if this by chance is the problem, because I hadn't tried it yet and I keep thinking... we know it's a local issue so it must be something like this.

所以我跳到了

C:\Zzzzz\yyyy\Qqqqqq\  

  • 效果很好!
  • 所以为了调试有问题的字符类型,我制作了一个文件夹来玩,并以空格开头...

    So to debug the type of character that is a problem, I made a folder to play with, and started with spaces...

    C:\Zzzzz\yyyy\Qqqqqq\a folder with spaces\  
    

    ==>错误!

    更改为相同长度但没有空格...

    Changing to same length but no spaces...

    C:\Zzzzz\yyyy\Qqqqqq\aFolderWithNooSpaces\  
    

    ==>好的 :) !!!

    我可能会检查其他特殊字符,但这已经足够调试了,我认为;-)
    我相信开发人员可以从这里拿走它.github 说他们关注了这个标签.

    I might check for other special characters, but this is already more than enough debugging, I think ;-)
    I'm sure the dev can take it from here. The github says they follow the tag.

    这篇关于RMarkdown 包 flextable 立即失败,并显示“read_docx only support docx";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆