2

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

Tom Carrick
  • 6,349
  • 13
  • 54
  • 78

1 Answers1

1

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")
  • Thanks Petr, for your response. I checked the change log and the change from ph_with_* to ph_with was done after version 0.3.2. I then installed 0.3.2 version, but I am getting the following error - Error: 'ph_with_flextable_at' is defunct. Use 'officer::ph_with' instead. See help("Defunct") In addition: Warning message: – Anshul Jain Jul 03 '20 at 13:33
  • @AnshulJain Hi Anshul, yeah, you are right. It seems you also have to install appropriate version of flextable, i.e. probably 0.5.6 or older, see their [flextable changelog](https://github.com/davidgohel/flextable/blob/master/NEWS) and [archive](https://cran.r-project.org/src/contrib/Archive/flextable/). Let me know if that works. –  Jul 03 '20 at 13:37
  • Hi Petr, with officer version of 0.3.2 and flextable version of 0.5.6, I am getting error. Not sure which two version combinations are compatible -Warning: replacing previous import ‘zip::unzip’ by ‘utils::unzip’ when loading ‘officer’ Error : object ‘ph_with’ is not exported by 'namespace:officer' ERROR: lazy loading failed for package ‘flextable’ – Anshul Jain Jul 03 '20 at 15:35
  • @AnshulJain I have tried to install `officer 0.3.2` with `flextable 0.4.4` (as they were out at similar time) and basic scripts with `ph_with_flextable_at()` work properly for me without any warning or error - I have updated the answer, please try. –  Jul 03 '20 at 16:04
  • 1
    Thanks Petr, the version combinations that you have mentioned in the example are working fine. Really appreciate your time on this. Thanks! – Anshul Jain Jul 07 '20 at 10:41
  • @AnshulJain Wow, great, thanks for your feedback, I'm glad it really works for you! –  Jul 07 '20 at 14:57