rreportersfootnotes

How can I add a footnote without any numbering in a *.docx file using ReporteRs?


When using the ReporteRs package, it seems that the only way to get text into the footer of a page involves placing a numbered footnote in the body of the text, and having that footnote appear with the same number in the footer. I'd like to be able to put text in the footer of a page without any numbering in front.

library(ReporteRs)

doc1 <- docx()
doc1 <- addFlexTable(doc1,vanilla.table(head(iris)))
Foot <- Footnote()
Foot <- addParagraph(Foot,"This should not have a number in front of it")
doc <- addParagraph(doc,pot("There should be no number after this",footnote=Foot))
writeDoc(doc1, file = "footnote1.docx")

Alternatively, if it's possible to just put a paragraph at the bottom of the page, that would also solve my problem. This could be done by figuring out how many more lines will fit on the page, but if there was some way to make the vertical alignment the bottom of the page for the last paragraph, that would be ideal.

doc2 <- docx()
doc2 <- addFlexTable(doc2,vanilla.table(head(iris)))
doc2 <- addParagraph(doc2,c(rep("",33),"Text placed by dynamically finding bottom of the page"))
writeDoc(doc2, file = "footnote2.docx")

Solution

  • What you are trying to do doesn't match ReporteRs::Footnote as it was written, as shown in the help:

    If in a docx object, footnote will be flagged by a number immediately following the portion of the text the note is in reference to.

    However, what you are after is achievable if I understand your question correctly. The note in your table and the text in the footer will not be connected in any way, such as a hyperlink provided by Footnote.

    There is also the issue that ReporteRs does not provide a method to place text in the footer without using bookmarks (except Footnote, which we have now discounted). That means we need to use a docx template instead of the empty document generated by the package.

    Template creation

    Steps:

    1. From MS Word I have opened an empty document
    2. Placed the cursor in the footer area
    3. Insert => Bookmark
    4. Enter Bookmark name, I just used FOOTER, and click Add
    5. Save the document

    enter image description here

    Document generation with ReporteRs

    With our new template, the next steps will seem more familiar.

    library(ReporteRs)
    
    doc <- docx(template = "Doc1.docx")
    
    # do the flextable, note that I add your table footer here
    ftable <- vanilla.table(head(iris))
    
    ftable <- addFooterRow(
      ftable,
      value = c("There should be no number after this"),
      colspan = 5
    )
    
    doc <- addFlexTable(doc, ftable)
    
    # check for the presence of our bookmark
    list_bookmarks(doc)
    # [1] "FOOTER"
    
    # now add the footer text using the bookmark
    doc <- addParagraph(
      doc, stylename = "footer", bookmark = "FOOTER",
      pot("This should not have a number in front of it")
    )
    
    # and finally write the document
    writeDoc(doc, file = "doc.docx")
    

    End product

    The table, which you can better format to suit, I have not removed the border on the added row.

    enter image description here

    The footer, in the standard footer style, which again you can modify to suit.

    enter image description here