Error with tex2docx function from R package reports

I am trying to reproduce an example for the tex2docx function in the reports R package and get the following error.

 DOC <- system.file("extdata/doc_library/apa6.qual_tex/doc.tex", package = "reports") BIB <- system.file("extdata/docs/example.bib", package = "reports") tex2docx(DOC, file.path(getwd(), "test.docx"), path = NULL, bib.loc = BIB) 

Error message

 pandoc.exe: Error reading bibliography `C:/Users/Muhammad' citeproc: the format of the bibliographic database could not be recognized using the file extension. docx file generated! Warning message: running command 'C:\Users\MUHAMM~1\AppData\Local\Pandoc\pandoc.exe -s C:/Users/Muhammad Yaseen/R/win-library/3.0/reports/extdata/doc_library/apa6.qual_tex/doc.tex -o C:/Users/Muhammad Yaseen/Documents/test.docx --bibliography=C:/Users/Muhammad Yaseen/R/win-library/3.0/reports/extdata/docs/example.bib' had status 23 

I wonder how to get the tex2docx function in the reports R package. Any help would be greatly appreciated. Thanks

+4
source share
1 answer

As described in the comments above, the error was caused by passing the file / path name, including some spaces that were not escaped or specified. The workaround may be to wrap all the paths and file names inside shQuote before going to the command line with system .

Code: https://github.com/trinker/reports/pull/31


Demo:

  • Download package

     library(reports) 
  • Creating a dummy directory with a space in the name containing the bib file

     dir.create('foo bar') file.copy(system.file("extdata/docs/example.bib", package = "reports"), 'foo bar/example.bib') 
  • Specifying the source and the copied bib file:

     DOC <- system.file("extdata/doc_library/apa6.qual_tex/doc.tex", package = "reports") BIB <- 'foo bar/example.bib' 
  • Test run:

     tex2docx(DOC, file.path(getwd(), "test2.docx"), path = NULL, bib.loc = BIB) 

Disclaimer: I tried to test this tensile request, but could not configure the environment with all the necessary tools to run the R CMD check with vignettes and everything else after 5 minutes (sorry, but being on vacation right now and enjoying the siesta after lunch), therefore, please consider this stretch request as “unverified”, although it should work.

+4
source

Source: https://habr.com/ru/post/1493800/


All Articles