Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fix #174 #175

Merged
merged 3 commits into from
Jun 16, 2023
Merged

bug fix #174 #175

merged 3 commits into from
Jun 16, 2023

Conversation

fb-elong
Copy link
Collaborator

@fb-elong fb-elong commented Jun 16, 2023

divided from 0 instead of 1 to allow first page to have same number of rows.

Root cause: divided by should start from 0 instead of 1 to get the same number of rows in the first page.

Example:

> 1:10 %/% 3
 [1] 0 0 1 1 1 2 2 2 3 3

Example code:

library(r2rtf)
#> Warning: package 'r2rtf' was built under R version 4.1.3
library(glue)
#> Warning: package 'glue' was built under R version 4.1.3
library(dplyr)
#> Warning: package 'dplyr' was built under R version 4.1.3
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
n_trt <- 100
n_placebo <- 50
# Create empty dataframe
df <- data.frame(matrix(ncol = 6, nrow = 200))

# Assign column names
colnames(df) <- c("Column1", "Column2", "Column3", "Column4", "Column5", "Column6")

# Generate random character data
set.seed(123)  # For reproducibility
for (i in 1:6) {
  df[, i] <- replicate(200, paste(sample(letters, 35, replace = TRUE), collapse = ""))
}

col_width <- c(5,3,3,3,3,3)

col_header <- c(
  "|Treatment 1| |Oddsd Ratio [1]|Relative Risk [1]|Risk Difference [1]",
  " |Only|Placebo|(95% CI)|(95% CI)|(95% CI)",
  glue('Preferred Term|(N={n_trt})|(N={n_placebo})|p-value|p-value|p-value')
)  

col_header <- purrr::map(col_header, function(x) strsplit(x, "|", fixed = TRUE)[[1]])
col_header <- do.call(cbind, col_header)
col_header <- paste(apply(col_header, 1, paste, collapse = "\n"), collapse = "|")
  
  
df %>%
  # rtf_page(orientation = "landscape") %>%
  rtf_page(orientation = "landscape",
           # width = ifelse(orientation == "portrait", 8.5, 11),
           # height = ifelse(orientation == "portrait", 11, 8.5),
           # nrow = ifelse(orientation == "portrait", 40, 24)
           width = 11,
           height = 8.5,
           nrow = 23
  ) %>%
  rtf_page_header(text = "[CONFIDENTIAL]                                                                                                                CSR \\line Protocol StudyID                                                                                                                   Page \\pagenumber of \\pagefield",
                  text_justification = "j",
                  text_font_size = 8,
                  text_convert = TRUE
  ) %>%
  rtf_footnote(
    footnote = c("Note: At each level of subject summarization, a subject is counted once for the most severe event if the subject reported one or more events. * Indicates p-value < 0.05. MedDRA 23.0 used for coding",
                 "[1] All odds ratios, relative risks and risk differences are for comparing the Cabozantinib only arm to the Placebo arm",
                 "All point estimates and confidence intervals are from Proc Freq, odds ratio p-values from Proc Logistic, Relative risk p-values from Proc Genmod and Risk difference CMH p-value from proc Freq. P-values for the odds ratio and relative risk are not generated unless the event rate is at least 5% in both the treatment arms.",
                 "Source Data: ADSL, ADAE",
                 "Data Cut Date: 19AUG2020 Data Extraction Date: 13NOV2020",
                 "Source: Data transfer: 20210316"
    ),
    as_table = FALSE, #If TRUE, the footnotes will be inside the table
    # text_space_before = 5,
    text_font_size = 7,
    text_convert = FALSE #Tell R don't interpret special characters
  ) %>%
  rtf_title(title = c(
    "Table 14.3.1.5.7.1",
    "Subject Incidence of Treatment-Emergent Adverse Events by Preferred Term with Odds Ratio, Relative Risk and Risk Difference",
    "(sorted by Descending Risk Difference)",
    "Population: Safety"
  ),
  text_font_size = 9
  ) %>%
  # rtf_subline(text= subline) %>%
  rtf_colheader(colheader = col_header,
                col_rel_width = col_width,
                border_left = "",
                border_right = "",
                border_bottom = "",
                text_font_size=8 ) %>%
  rtf_body(col_rel_width = col_width,
           text_justification = c('l',rep('c',5)),
           border_left = "",
           border_right = "",
           text_font_size=8) %>%
  rtf_encode(page_footnote = 'all') %>%
  write_rtf(paste0("test1",".rtf"))

Output:

image

divided from 0 instead of 1 to allow first page to have same number of rows.
Copy link
Collaborator

@nanxstats nanxstats left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The patch looks good. All CI workflows need to pass, though. Can you check if any snapshot tests are failing? I read from this testthat issue that the cryptic error Error in trace_back(top = getOption("testthat_topenv"), bottom = trace_env): Can't find bottom on the call tree. means that the snapshot tests are actually failing.

@elong0527
Copy link
Collaborator

I am not able to reproduce the issue. The test has all been passed in posit cloud.

The reference link mentioned a upload-snapshots parameter, would you think test-package CI can also enable it to help us get more informative message from the output?

Alternatively, let me try to remove the snaps and see if it only apply to the new change.

Merge branch 'master' of https://github.com/Merck/r2rtf into bug-fix-174

# Conflicts:
#	tests/testthat/_snaps/independent-testing-rtf_encode_list.md
Copy link
Collaborator

@nanxstats nanxstats left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's working after the snapshots are deleted! Could be from there.

@nanxstats nanxstats merged commit a41cc93 into master Jun 16, 2023
@nanxstats nanxstats deleted the bug-fix-174 branch June 16, 2023 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants