Skip to content

Commit f1be22f

Browse files
authored
Merge pull request #269 from Merck/feature/issue-235-text-hyphenation
Feature/issue 235 text hyphenation
2 parents be664f7 + b6d5225 commit f1be22f

64 files changed

Lines changed: 706 additions & 583 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CLAUDE.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Project Context for r2rtf
2+
3+
## Overview
4+
This is an R package for generating RTF (Rich Text Format) tables, figures, and listings. As a senior data scientist maintaining this package, I should be familiar with RTF syntax and R package development best practices.
5+
6+
## Key Information
7+
- **Package Purpose**: Generate RTF tables, figures, and listings programmatically in R
8+
- **Domain**: Clinical trial reporting and data visualization
9+
- **RTF Expertise**: Understanding of RTF syntax and specification is essential
10+
- **R Version**: 4.5.1 on macOS (aarch64-apple-darwin24.4.0)
11+
12+
## Development Guidelines
13+
- Follow R package development best practices
14+
- Maintain backward compatibility when possible
15+
- Ensure RTF output conforms to specification
16+
- Test thoroughly with various table/figure configurations
17+
- Always run tests before committing changes
18+
19+
## Development Workflow Commands (using devtools)
20+
- Load package for development: `devtools::load_all()`
21+
- Run all tests: `devtools::test()`
22+
- Run specific tests: `devtools::test(filter = "rtf_title")`
23+
- Build package: `devtools::build()`
24+
- Check package: `devtools::check()`
25+
- Generate/update documentation: `devtools::document()` or `roxygen2::roxygenise()`
26+
- Install package locally: `devtools::install()`
27+
- Build pkgdown site: `pkgdown::build_site()` or `devtools::build_site()`
28+
- Build reference only: `pkgdown::build_reference()`
29+
- Build articles only: `pkgdown::build_articles()`
30+
31+
## System Dependencies (macOS with Homebrew)
32+
Required system libraries for development:
33+
- `libgit2` - for gert package
34+
- `harfbuzz`, `fribidi` - for textshaping package
35+
- `freetype`, `libpng`, `libtiff`, `libjpeg-turbo` - for ragg package
36+
- `pkg-config` - for package configuration
37+
- `pandoc` - for building documentation and vignettes
38+
39+
Install with: `brew install libgit2 harfbuzz fribidi freetype libpng libtiff libjpeg-turbo pkg-config pandoc`
40+
41+
## Package Installation
42+
For better dependency management, use `pak`:
43+
```r
44+
# Install pak if not available
45+
install.packages("pak", repos = "https://r-lib.github.io/p/pak/stable/")
46+
47+
# Install development tools
48+
pak::pkg_install(c("devtools", "tidyverse", "testthat", "roxygen2", "pkgdown", "emmeans"))
49+
```
50+
51+
## Key Functions Being Maintained
52+
- `rtf_title()` - Add title attributes to tables
53+
- `rtf_colheader()` - Add column header attributes to tables
54+
- `rtf_subline()` - Add subline attributes to tables
55+
- `rtf_body()` - Format table body
56+
- `rtf_footnote()` - Add footnotes to tables
57+
- `rtf_source()` - Add source information to tables
58+
- `rtf_page()` - Set page attributes
59+
60+
## Recent Changes
61+
- **Issue #235**: Added `text_hyphenation` parameter to `rtf_title()`, `rtf_colheader()`, and `rtf_subline()` functions
62+
- Default value is `TRUE` for backward compatibility
63+
- Allows users to control text hyphenation in RTF output
64+
- Branch: `feature/issue-235-text-hyphenation`
65+
66+
## Important Files
67+
- DESCRIPTION: Package metadata
68+
- NAMESPACE: Exported functions
69+
- R/: Source code
70+
- tests/testthat/: Unit tests
71+
- man/: Documentation (auto-generated by roxygen2)
72+
- vignettes/: Package vignettes
73+
- inst/: Additional package files
74+
75+
## Testing Approach
76+
- Unit tests using `testthat` framework
77+
- Test files named `test-independent-testing-*.R`
78+
- Snapshot tests for complex output validation
79+
- Always verify changes don't break existing functionality

R/rtf_colheader.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#' Default is NULL for a blank column header.
2323
#' @param col_rel_width A Column relative width in a vector e.g. c(2,1,1) refers to 2:1:1.
2424
#' Default is NULL for equal column width.
25+
#' @param text_hyphenation A logical value to control whether display text linked with hyphenation.
2526
#' @inheritParams rtf_footnote
2627
#'
2728
#' @section Specification:
@@ -77,6 +78,7 @@ rtf_colheader <- function(tbl,
7778
text_space = 1,
7879
text_space_before = 15,
7980
text_space_after = 15,
81+
text_hyphenation = TRUE,
8082
text_convert = TRUE) {
8183
# Check argument type
8284
check_args(tbl, type = c("data.frame"))
@@ -118,7 +120,7 @@ rtf_colheader <- function(tbl,
118120
text_space_before,
119121
text_space_after,
120122
text_new_page = FALSE,
121-
text_hyphenation = TRUE,
123+
text_hyphenation = text_hyphenation,
122124
text_convert = text_convert
123125
)
124126
if (attr(colheader, "use_color")) attr(tbl, "page")$use_color <- TRUE

R/rtf_title.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#' @param tbl A data frame.
2424
#' @param title Title in a character string.
2525
#' @param subtitle Subtitle in a character string.
26+
#' @param text_hyphenation A logical value to control whether display text linked with hyphenation.
2627
#' @inheritParams rtf_footnote
2728
#'
2829
#' @section Specification:
@@ -61,6 +62,7 @@ rtf_title <- function(tbl,
6162
text_space = 1,
6263
text_space_before = 180,
6364
text_space_after = 180,
65+
text_hyphenation = TRUE,
6466
text_convert = TRUE) {
6567
# check argument types
6668
check_args(title, type = c("character"))
@@ -99,7 +101,7 @@ rtf_title <- function(tbl,
99101
text_space_before,
100102
text_space_after,
101103
text_new_page = FALSE,
102-
text_hyphenation = TRUE,
104+
text_hyphenation = text_hyphenation,
103105
text_convert = text_convert
104106
)
105107

@@ -119,6 +121,7 @@ rtf_title <- function(tbl,
119121
#'
120122
#' @param tbl A data frame.
121123
#' @param text A character vector of subline
124+
#' @param text_hyphenation A logical value to control whether display text linked with hyphenation.
122125
#' @inheritParams rtf_footnote
123126
#'
124127
#' @section Specification:
@@ -148,6 +151,7 @@ rtf_subline <- function(tbl,
148151
text_space = 1,
149152
text_space_before = 180,
150153
text_space_after = 180,
154+
text_hyphenation = TRUE,
151155
text_convert = TRUE) {
152156
# Input checking
153157
check_args(text, type = c("character"))
@@ -182,7 +186,7 @@ rtf_subline <- function(tbl,
182186
text_space_before,
183187
text_space_after,
184188
text_new_page = FALSE,
185-
text_hyphenation = TRUE,
189+
text_hyphenation = text_hyphenation,
186190
text_convert = text_convert
187191
)
188192

man/rtf_colheader.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/rtf_subline.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/rtf_title.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-independent-testing-rtf_colheader.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ test_that("border type", {
4949
expect_equal(attr(attr(x, "rtf_colheader")[[2]], "border_left")[1, ], c("double", "single", "dot dot"))
5050
})
5151

52+
test_that("text hyphenation parameter", {
53+
# Test default value (TRUE)
54+
x <- r2rtf_tbl1 |> rtf_colheader(colheader = "Column 1 | Column 2 | Column 3")
55+
expect_equal(attr(attr(x, "rtf_colheader")[[1]], "text_hyphenation"), TRUE)
56+
57+
# Test explicitly setting to FALSE
58+
x <- r2rtf_tbl1 |> rtf_colheader(colheader = "Column 1 | Column 2 | Column 3", text_hyphenation = FALSE)
59+
expect_equal(attr(attr(x, "rtf_colheader")[[1]], "text_hyphenation"), FALSE)
60+
61+
# Test explicitly setting to TRUE
62+
x <- r2rtf_tbl1 |> rtf_colheader(colheader = "Column 1 | Column 2 | Column 3", text_hyphenation = TRUE)
63+
expect_equal(attr(attr(x, "rtf_colheader")[[1]], "text_hyphenation"), TRUE)
64+
})
65+
5266

5367
test_that("cell text formats", {
5468
x <- r2rtf_tbl1 |>

tests/testthat/test-independent-testing-rtf_title.R

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,24 @@ test_that("multiple subtitles", {
6060
expect_equal(attributes(x)$rtf_title[[2]], "Sub-Title 2")
6161
expect_equal(attributes(x)$rtf_title[[3]], "Sub-Title 3")
6262
})
63+
64+
test_that("text hyphenation parameter", {
65+
# Test default value (TRUE)
66+
x <- r2rtf_tbl1 |> rtf_title(title = "Title with Hyphenation")
67+
expect_equal(attr(attr(x, "rtf_title"), "text_hyphenation"), TRUE)
68+
69+
# Test explicitly setting to FALSE
70+
x <- r2rtf_tbl1 |> rtf_title(title = "Title without Hyphenation", text_hyphenation = FALSE)
71+
expect_equal(attr(attr(x, "rtf_title"), "text_hyphenation"), FALSE)
72+
73+
# Test explicitly setting to TRUE
74+
x <- r2rtf_tbl1 |> rtf_title(title = "Title with Hyphenation", text_hyphenation = TRUE)
75+
expect_equal(attr(attr(x, "rtf_title"), "text_hyphenation"), TRUE)
76+
77+
# Test with rtf_subline
78+
x <- r2rtf_tbl1 |> rtf_subline(text = "Subline with default hyphenation")
79+
expect_equal(attr(attr(x, "rtf_subline"), "text_hyphenation"), TRUE)
80+
81+
x <- r2rtf_tbl1 |> rtf_subline(text = "Subline without hyphenation", text_hyphenation = FALSE)
82+
expect_equal(attr(attr(x, "rtf_subline"), "text_hyphenation"), FALSE)
83+
})

vignettes/fig/intro-fig1.png

-28 Bytes
Loading

vignettes/rtf/ae_example.rtf

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)