diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 0d3b251..3ca1b94 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -36,9 +36,9 @@ jobs: - {os: windows-latest, r: 'oldrel-1'} # Use older ubuntu to maximise backward compatibility - - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} - - {os: ubuntu-latest, r: 'release'} - - {os: ubuntu-latest, r: 'oldrel'} + #- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} + #- {os: ubuntu-latest, r: 'release'} + #- {os: ubuntu-latest, r: 'oldrel'} env: @@ -57,6 +57,21 @@ jobs: http-user-agent: ${{ matrix.config.http-user-agent }} use-public-rspm: true + - name: install freetype2 and imagemagick deps and libreoffice + if: matrix.config.os == 'macOS-latest' + run: | + brew install --cask libreoffice + + - name: install libreoffice for ubuntu + if: matrix.config.os == 'ubuntu-latest' + run: | + sudo apt install libreoffice + + - name: install libreoffice for windows + if: matrix.config.os == 'windows-latest' + run: | + choco install libreoffice-fresh -y + - uses: r-lib/actions/setup-r-dependencies@v2 with: extra-packages: rcmdcheck diff --git a/.github/workflows/R-CMD-release.yaml b/.github/workflows/R-CMD-release.yaml index 86216ef..e3bb793 100644 --- a/.github/workflows/R-CMD-release.yaml +++ b/.github/workflows/R-CMD-release.yaml @@ -8,6 +8,8 @@ jobs: steps: - uses: actions/checkout@v2 - uses: r-lib/actions/setup-r@v2 + - name: install freetype2 and imagemagick deps and libreoffice + run: brew install --cask libreoffice - name: Install dependencies run: | install.packages(c("remotes", "rcmdcheck")) diff --git a/DESCRIPTION b/DESCRIPTION index 7aa265e..0cfdf75 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,12 +1,17 @@ Package: SwissASR Title: Automated Completion of the SwissEthics Annual Safety Report -Version: 0.3.0 +Version: 0.4.0 Authors@R: - person(given = "Alan G.", + c(person(given = "Alan G.", family = "Haynes", role = c("aut", "cre"), - email = "alan.haynes@ctu.unibe.ch", - comment = c(ORCID = "0000-0003-1374-081X")) + email = "alan.haynes@unibe.ch", + comment = c(ORCID = "0000-0003-1374-081X")), + person(given = "Mattia", + family = "Branca", + role = "ctb", + email = "mattia.branca@unibe.ch", + comment = c(ORCID = "0000-0002-8063-7882")) ) Description: Completing the SwissEthics Annual Safety Report can be tiresome. This package eases the pain by providing an automated method to fill it out. License: MIT + file LICENSE Encoding: UTF-8 @@ -21,4 +26,5 @@ Imports: magrittr, officer, stringr, - tibble + tibble, + doconv diff --git a/NAMESPACE b/NAMESPACE index 2c9ac78..a319343 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,6 +5,7 @@ export(asr_dataprep) export(asr_safety_summary) import(flextable) import(officer) +importFrom(doconv,docx_update) importFrom(glue,glue) importFrom(magrittr,"%>%") importFrom(stringr,str_to_lower) diff --git a/NEWS.md b/NEWS.md index 2f4d487..4fcebe1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,15 +1,20 @@ -# swissethics 0.3.0 +# SwissASR 0.4.0 + +* Modified some bookmarks into word fields such that the replacement can still happen in tables and not after them, as per recent update of officer package. This resolves issue #9. +* The above change requires use of the `doconv` package, which may require **setting some permissions on MAC OS** (for details see [the doconv documentation](https://github.com/ardata-fr/doconv)), and **may not work on Ubuntu** systems. + +# SwissASR 0.3.0 * Additional option to include an intervention (random allocation) variable into the line listing (option `var_tx`), which is sometimes requested by ethics bodies. * Addition of a logo -# swissethics 0.2.0 +# SwissASR 0.2.0 * Addition of `asr_dataprep` and `asr_safety_summary` functions allowing for production of tables without generation of the MS Word report. * Reworking of the internals of `asr` to utilise the above mentioned functions. * Addition of demonstration dataset. * Line listing pages in the word template set to landscape. -# swissethics 0.1.0 +# SwissASR 0.1.0 * Added a `NEWS.md` file to track changes to the package. diff --git a/R/asr.R b/R/asr.R index aee70c2..652610f 100644 --- a/R/asr.R +++ b/R/asr.R @@ -122,6 +122,7 @@ #' @importFrom tibble tribble #' @importFrom glue glue #' @importFrom stringr str_to_lower str_to_sentence +#' @importFrom doconv docx_update #' @examples #' #' data(asr_sae) @@ -202,7 +203,7 @@ asr <- function(data, , report_date = format(Sys.Date(), format = "%d/%m/%Y") , period_from = as.Date("2020-11-02") , period_to = as.Date("2020-11-17") - , template = system.file("extdata/clino_annual_safety_report_bm.docx", package = "SwissASR") + , template = system.file("extdata/clino_annual_safety_report_fm.docx", package = "SwissASR") , international = FALSE , trial_type = "imp" # dataframe variables @@ -394,49 +395,72 @@ asr <- function(data, # ..general info, details of trial ---- - period <- glue("{period_from} to {period_to}") - - for(i in c("trial_title", - "protocol_number", - "basec_number", - "snctp_number", - "swissmedic_number", - "ec_name", - "product_name", - "sponsor_contact", - "inst_name_address", - "report_date", - "period", - "n_centers_t", - "n_centers_p", - "n_centers_c", - "n_centers_o", - "n_pat_t", - "n_pat_e", - "n_pat_c", - "n_pat_p")){ - x <- get(i) - doc <- doc %>% - cursor_bookmark(i) %>% - body_add_par(x, pos = "after") - } - - - + # + # for(i in c("trial_title", + # "protocol_number", + # "basec_number", + # "snctp_number", + # "swissmedic_number", + # "ec_name", + # "product_name", + # "sponsor_contact", + # "inst_name_address", + # "report_date", + # "period", + # "n_centers_t", + # "n_centers_p", + # "n_centers_c", + # "n_centers_o", + # "n_pat_t", + # "n_pat_e", + # "n_pat_c", + # "n_pat_p")){ + # x <- get(i) + # doc <- doc %>% + # cursor_bookmark(i) %>% + # body_add_par(x, pos = "after") + # } - ## participant safety ---- + period <- glue("{period_from} to {period_to}") +## New code to insert the fields instead of bookmarks + doc <- doc %>% + set_doc_properties(trial_title = get("trial_title"), + protocol_number = get("protocol_number"), + basec_number = get("basec_number"), + snctp_number = get("snctp_number"), + swissmedic_number = get("swissmedic_number"), + ec_name = get("ec_name"), + product_name = get("product_name"), + sponsor_contact = get("sponsor_contact"), + inst_name_address = get("inst_name_address"), + report_date = get("report_date"), + period = get("period"), + n_centers_t = get("n_centers_t"), + n_centers_p = get("n_centers_p"), + n_centers_c = get("n_centers_c"), + n_centers_o = get("n_centers_o"), + n_pat_t = as.character(n_pat_t), + n_pat_e = as.character(n_pat_e), + n_pat_c = as.character(n_pat_c), + n_pat_p = as.character(n_pat_p) ) + + + #} ## participant safety ---- summ <- asr_safety_summary(data = data, period_data = period_data, trial_type = trial_type, n_pat_e = n_pat_e) + # doc <- doc %>% + # cursor_bookmark("partsafety_text") + # for(i in 1:length(summ$txt)){ + # txt <- summ$txt[i] + # doc <- doc %>% body_add_par(txt, style = "Text") + # } + doc <- doc %>% - cursor_bookmark("partsafety_text") - for(i in 1:length(summ$txt)){ - txt <- summ$txt[i] - doc <- doc %>% body_add_par(txt, style = "Text") - } + officer::set_doc_properties(partsafety_text = paste0(summ$txt, collapse = " ") ) # map <- data.frame( # col_key = c("x1", "x2", "x3", "x4", "x5"), @@ -613,6 +637,11 @@ asr <- function(data, print(doc, target = target) + doc <- doc %>% + doc_properties() + + docx_update(input = target) + } diff --git a/README.Rmd b/README.Rmd index a1702e8..3083886 100644 --- a/README.Rmd +++ b/README.Rmd @@ -16,7 +16,7 @@ knitr::opts_chunk$set(echo = TRUE) Participant safety is a big issue in clinical trials and reporting safety related events to the authorities is mandatory for certain trial types. One aspect of this is the annual safety report (ASR) which contains both summary information and listings of safety events. The `SwissASR` R package helps in compiling this report. -Provide a dataframe with the given variables and the function will return a filled out (as far as possible - some things require PI input) ASR in MS Word format. This could then be forwarded to the PI for supplimental details, signing and submission to the relevant governing bodies. +Provide a dataframe with the given variables and the function will return a filled out (as far as possible - some things require PI input) ASR in MS Word format. This could then be forwarded to the PI for supplemental details, signing and submission to the relevant governing bodies. ## Example usage diff --git a/inst/extdata/clino_annual_safety_report_bm.docx b/inst/extdata/clino_annual_safety_report_bm.docx index a03bfd4..1ac1fbf 100644 Binary files a/inst/extdata/clino_annual_safety_report_bm.docx and b/inst/extdata/clino_annual_safety_report_bm.docx differ diff --git a/inst/extdata/clino_annual_safety_report_fm.docx b/inst/extdata/clino_annual_safety_report_fm.docx new file mode 100644 index 0000000..b18cac9 Binary files /dev/null and b/inst/extdata/clino_annual_safety_report_fm.docx differ diff --git a/man/asr.Rd b/man/asr.Rd index 64d84a2..96ea669 100644 --- a/man/asr.Rd +++ b/man/asr.Rd @@ -27,7 +27,7 @@ asr( report_date = format(Sys.Date(), format = "\%d/\%m/\%Y"), period_from = as.Date("2020-11-02"), period_to = as.Date("2020-11-17"), - template = system.file("extdata/clino_annual_safety_report_bm.docx", package = + template = system.file("extdata/clino_annual_safety_report_fm.docx", package = "SwissASR"), international = FALSE, trial_type = "imp",