Search code examples
rofficer

Officer package in R


All the ph_with_* functions have been deprecated. Is there a way if I can still use the old version of officer and flextable which will allow me to use ph_with_* functions. I have an automated process and due to the new version, I am having a hard time making all the changes


Solution

  • It should be possible. If you know the particular version number (you can check the changelog), just look to the archive, copy the URL of your version and run e.g.:

    install.packages("https://cran.r-project.org/src/contrib/Archive/officer/officer_0.1.0.tar.gz",
                     repos = NULL, type = "source")
    

    Or use devtools package:

    devtools::install_version("officer",
                              version = "0.1.0",
                              repos = "http://cran.r-project.org")
    

    The same comes for flextable package with its changelog and CRAN archive.

    Example

    I have tried the following:

    devtools::install_version("officer",
                              version = "0.3.2",
                              repos = "http://cran.r-project.org")
    devtools::install_version("officer",
                              version = "0.4.4",
                              repos = "http://cran.r-project.org")
    

    And the example with ph_with_flextable_at() from the documentation works properly:

    library(officer)
    library(flextable)
    ft <- flextable(head(mtcars))
    
    doc <- read_pptx()
    doc <- add_slide(doc, layout = "Title and Content",
                     master = "Office Theme")
    doc <- ph_with_flextable(doc, value = ft, type = "body")
    doc <- ph_with_flextable_at(doc, value = ft, left = 4, top = 5)
    print(doc, target = "test.pptx")