Skip to content

📃🗣️ R package: Word to Govspeak [WIP]

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

matt-dray/wordup

Repository files navigation

{wordup}

Project Status: Concept – Minimal or no implementation has been done yet, or the repository is only intended to be a limited example, demo, or proof-of-concept. R-CMD-check Blog post

Purpose

Convert a Microsoft Word document (docx) to Govspeak Markdown, which is the format required to publish on GOV.UK.

This package is a personal project for learning purposes. It may never be finished and has no guarantees.

You may also be interested in a demo Shinylive app for converting tables to Govspeak format.

Motivation and scope

Producers of statistical publications might draft their reports in docx format. Publishers need to convert these to Govspeak Markdown so they can be uploaded to the Government’s publishing platform. This can be time consuming to do manually and there is potential for error. There’s a Govspeak converter tool, but there’s some missing functionality, such as handling images and tables.

Installation

The package is available from GitHub. It isn’t stable.

install.packages("remotes")  # if not yet installed
remotes::install_github("matt-dray/wordup")

Here’s the list structure of an example word/document.xml from an unzipped docx file.

library(wordup)
path <- system.file("examples/simple.docx", package = "wordup")
body_list <- wu_read(path)
str(body_list, give.attr = FALSE, max.level = 3)
# List of 1
#  $ document:List of 1
#   ..$ body:List of 15
#   .. ..$ p     :List of 2
#   .. ..$ p     :List of 3
#   .. ..$ p     :List of 5
#   .. ..$ p     :List of 3
#   .. ..$ p     :List of 1
#   .. ..$ p     :List of 2
#   .. ..$ p     :List of 2
#   .. ..$ p     :List of 3
#   .. ..$ p     :List of 1
#   .. ..$ tbl   :List of 5
#   .. ..$ p     :List of 3
#   .. ..$ p     :List of 4
#   .. ..$ p     :List of 1
#   .. ..$ p     :List of 1
#   .. ..$ sectPr:List of 4

We can delve into this structure to retrieve text, etc.

body_list$document$body[[5]]
# $r
# $r$t
# $r$t[[1]]
# [1] "This is some more text. This time with bullets:"
# 
# 
# 
# attr(,"paraId")
# [1] "2460A889"
# attr(,"textId")
# [1] "3361B78B"
# attr(,"rsidR")
# [1] "007D458C"
# attr(,"rsidRDefault")
# [1] "007D458C"

Hopefully {wordup} will get functions to grab text and styles, apply Govspeak styling and then output a Markdown file. It could also convert images to SVG and insert anchor links for them.

Related

There are existing packages that can convert R Markdown to Govspeak:

For handling Word documents in R:

  • {officer} can read a Word document to a tidy table
  • {docxtractr} can extract tables, comments and other things

About

📃🗣️ R package: Word to Govspeak [WIP]

Topics

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Languages