Comments (4)
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.
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.
from r2rtf.
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.
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
Line 69 in 9e68fa9
from r2rtf.
Related Issues (20)
- border_first & page_by HOT 3
- Variations in RTF output across package versions HOT 1
- rtf_subline & page_by HOT 2
- Stop assemble_rtf applying header/footer from last .rtf to entire document HOT 7
- Recreating HAMD17 data HOT 1
- Set different border widths within a section HOT 4
- Remove border between the header and body HOT 1
- Is it possible to add a long free text? HOT 5
- Create FAQ vignette HOT 2
- Refresh RTF and derived artifacts under `vignettes/`
- Release r2rtf 1.1.1 HOT 1
- Garbled code about Chinese character HOT 4
- Unnecessary SVG saving in tests?
- Logo.png in page header for summary tables- RTF format HOT 7
- Page Spread HOT 1
- strings dependency HOT 3
- Replace Unicode / LaTeX conversion table with R script HOT 2
- Cannot handle Chinese characters HOT 4
- Release r2rtf 1.1.2
- Blank `Rplots.pdf` generated when running snapshot tests interactively from RStudio HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from r2rtf.