Giter VIP home page Giter VIP logo

Comments (4)

elong0527 avatar elong0527 commented on August 15, 2024

Thanks @BrianLang , I feel we can implement the function into r2rtf.

We need to add a warning/error when there are different value for the page direction.

We also need to add few testing cases to ensure it works.

from r2rtf.

fb-elong avatar fb-elong commented on August 15, 2024

Would like to follow-up on this open item.

We will need the function for a new chapter in r4csr book. Currently I just add the function inside of the chapter.

elong0527/r4csr#82

from r2rtf.

BrianLang avatar BrianLang commented on August 15, 2024

Will update with Nan's implementation

may be able to keep each pages orientation with something like:
https://stackoverflow.com/questions/66795576/making-word-documents-a3-and-landscape-orientation-with-officer-r-package
for a future PR

#' Assemble RTF TLFs
#'
#' Add a set of RTF/TEXT fields into an rdocx object.
#'
#' @param input Character vector of file path.
#' @param output Character string to the output file path.
#' @param landscape Logical vector to determine whether to
#' display files as portrait or landscape.
#'
#' @section Specification:
#' \if{latex}{
#'   \itemize{
#'     \item Transfer files to toggle fields format in Word
#'     \item Insert into Word file using officer
#'   }
#' }
#' \if{html}{
#' The contents of this section are shown in PDF user manual only.
#' }
#'
#' @examples
#' \dontrun{
#' rtf_assemble(
#'   list.files(
#'     "outtable/",
#'     pattern = "*.rtf",
#'     full.names = TRUE
#'   ),
#'   output = "tmp.docx"
#' )
#' }
#'
#' @export
rtf_assemble <- function(input, output, landscape = FALSE) {
  input <- normalizePath(input)

  if (!all(file.exists(input))) {
    warning("Some files do not exist")
  }

  field <- ifelse(grepl("/", input),
    paste0("INCLUDETEXT \"", gsub("/", "\\\\\\\\", input), "\""),
    paste0("INCLUDETEXT \"", gsub("\\", "\\\\", input, fixed = "TRUE"), "\"")
  )

  if (length(landscape) == 1) {
    landscape <- rep(landscape, length(field))
  }

  docx <- officer::read_docx()

  for (i in seq_along(input)) {
    docx <-
      docx %>%
      officer::body_add_fpar(
        officer::fpar(
          officer::ftext("Table "),
          officer::run_word_field("SEQ Table \\* ARABIC"),
          officer::run_linebreak(),
          officer::run_word_field(field[i]),
          officer::run_pagebreak()
        )
      )
    if (landscape[i]) {
      docx <- officer::body_end_section_landscape(docx)
    } else {
      docx <- officer::body_end_section_portrait(docx)
    }
  }

  print(docx, target = output)

  invisible(output)
}

from r2rtf.

elong0527 avatar elong0527 commented on August 15, 2024

Yes, we are able to control page orientation using the function with officer.

You can refer the example in https://r4csr.org/assemble.html

One concern is to introduce officer as an r2rtf "import" dependency. One way is to implement both methods and detect officer dependency on the fly. Here is one way I leverage stringi

convert <- function(text,

from r2rtf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.