Brian Brummer
Brian Brummer

Reputation: 98

Unable to find file 'path/NA' when knitting to word_document2 using tbl_summary but works for PDF, HTML etc

before you click "next", this is not a path file error.

I am building on a blogpost: https://labrtorian.com/2019/08/26/rmarkdown-template-that-manages-academic-affiliations/

It works well for scientific papers.

My problem is:

In Rmarkdown when calling a data frame I am returned with the error about not being able to find file 'path/NA'


    ---
   
    output:
     bookdown::word_document2:
        pandoc_args:
          - --reference-doc=Extras/Reference_Document.docx 
        keep_tex: TRUE

    ---



    ```{r MRE}
    
    library(gtsummary)
    a <- c(10,20,30,40)
    b <- c('book', 'pen', 'textbook', 'pencil_case')
    c <- c(TRUE,FALSE,TRUE,FALSE)
    d <- c(2.5, 8, 10, 7)
    df <- data.frame(a,b,c,d)
    
    tbl_summary(df)
    tbl_summary
    

which returns:

Error: could not find file '/Users/brianbrummer/Documents/Rstudio/Affilitations_template/NA' Execution halted

So what gives? I would usually know how to fix a "path not found" error, but not a file...and the file is NA?

files referenced in YAML can be found:

https://github.com/bridaybrummer/author_affiliations_extras.git

Thanks in advance

Upvotes: 1

Views: 132

Answers (1)

Daniel D. Sjoberg
Daniel D. Sjoberg

Reputation: 11774

I did some digging and found the issue and a solution. First, if you update your yaml to call the reference document like this, you won't get the error any longer.

---
output:
  word_document:
    reference_doc: Reference_Document.docx
---

The issue was with the flextable package. If you're looking for community service points, you can post this reprex to their github page to alert them to the issue.

---
output:
  word_document:
    pandoc_args:
      - --reference-doc=Reference_Document.docx 
---

```{r MRE}
mtcars |> 
  flextable::flextable()
```

Upvotes: 1

Related Questions