From 0620b9d58a4bcdf51f3f12512d8ab6cbf5451517 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Sun, 14 Apr 2024 10:27:40 -0500 Subject: [PATCH 1/6] Some minor tweaks for convert() 1. Use `requireNamespace()` to test if stringi is available. 2. Reduce one `ifelse()` call. 3. Use the safer `seq_along(x)` instead of `1:length(x)`. --- R/conversion.R | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/R/conversion.R b/R/conversion.R index 5eb7c51..0953402 100644 --- a/R/conversion.R +++ b/R/conversion.R @@ -70,7 +70,7 @@ cell_size <- function(col_rel_width, col_total_width) { #' #' @noRd convert <- function(text, - load_stringi = class(try(stringi::stri_replace_all_fixed, silent = TRUE)) != "try-error") { + load_stringi = requireNamespace("stringi", quietly = TRUE)) { # grepl(">|<|=|_|\\^|(\\\\)|(\\n)", c(">", "<", "=", "_", "\n", "\\line", "abc")) index <- grepl(">|<|=|_|\\^|(\\\\)|(\\n)", text) @@ -91,12 +91,9 @@ convert <- function(text, # Define Pattern for latex code - unicode_latex$int <- as.integer(as.hexmode(unicode_latex$unicode)) - char_latex <- ifelse(unicode_latex$int <= 255 & unicode_latex$int != 177, unicode_latex$chr, - ifelse(unicode_latex$int < 32768, - paste0("\\uc1\\u", unicode_latex$int, "*"), - paste0("\\uc1\\u", unicode_latex$int - 65536, "*") - ) + unicode_int <- as.integer(as.hexmode(unicode_latex$unicode)) + char_latex <- ifelse(unicode_int <= 255 & unicode_int != 177, unicode_latex$chr, + paste0("\\uc1\\u", unicode_int - if (unicode_int < 32768) 0 else 65536, "*") ) names(char_latex) <- unicode_latex$latex @@ -108,7 +105,7 @@ convert <- function(text, vectorize_all = FALSE, opts_fixed = list(case_insensitive = FALSE) ) } else { - for (i in 1:length(char_latex)) { + for (i in seq_along(char_latex)) { text[index] <- gsub(names(char_latex[i]), char_latex[i], text[index], fixed = TRUE) } } From 832459219156894829d25ae399ef070ffde91bbd Mon Sep 17 00:00:00 2001 From: yilong zhang Date: Sun, 14 Apr 2024 17:32:02 -0400 Subject: [PATCH 2/6] Update R/conversion.R Co-authored-by: Yihui Xie --- R/conversion.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/conversion.R b/R/conversion.R index 0953402..1bb6ddd 100644 --- a/R/conversion.R +++ b/R/conversion.R @@ -93,7 +93,7 @@ convert <- function(text, unicode_int <- as.integer(as.hexmode(unicode_latex$unicode)) char_latex <- ifelse(unicode_int <= 255 & unicode_int != 177, unicode_latex$chr, - paste0("\\uc1\\u", unicode_int - if (unicode_int < 32768) 0 else 65536, "*") + sprintf("\\uc1\\u%d*", unicode_int - if (unicode_int < 32768) 0 else 65536) ) names(char_latex) <- unicode_latex$latex From f999506a5830c79331224e85bf19351db4bb996a Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Mon, 15 Apr 2024 10:12:49 -0500 Subject: [PATCH 3/6] `unicode_int` is a vector Co-authored-by: yilong zhang --- R/conversion.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/conversion.R b/R/conversion.R index 1bb6ddd..67a46a2 100644 --- a/R/conversion.R +++ b/R/conversion.R @@ -93,7 +93,7 @@ convert <- function(text, unicode_int <- as.integer(as.hexmode(unicode_latex$unicode)) char_latex <- ifelse(unicode_int <= 255 & unicode_int != 177, unicode_latex$chr, - sprintf("\\uc1\\u%d*", unicode_int - if (unicode_int < 32768) 0 else 65536) + sprintf("\\uc1\\u%d*", unicode_int - ifelse (unicode_int < 32768, 0, 65536)) ) names(char_latex) <- unicode_latex$latex From a198ffbffa5263e484199bad847e36d7750df000 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Mon, 15 Apr 2024 10:40:56 -0500 Subject: [PATCH 4/6] remove an extra space after `ifelse` since `ifelse` is a function --- R/conversion.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/conversion.R b/R/conversion.R index 67a46a2..0529cfe 100644 --- a/R/conversion.R +++ b/R/conversion.R @@ -93,7 +93,7 @@ convert <- function(text, unicode_int <- as.integer(as.hexmode(unicode_latex$unicode)) char_latex <- ifelse(unicode_int <= 255 & unicode_int != 177, unicode_latex$chr, - sprintf("\\uc1\\u%d*", unicode_int - ifelse (unicode_int < 32768, 0, 65536)) + sprintf("\\uc1\\u%d*", unicode_int - ifelse(unicode_int < 32768, 0, 65536)) ) names(char_latex) <- unicode_latex$latex From 408cba0ecb3b9ca98980691c3e517fa1da3a3435 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Tue, 16 Apr 2024 00:58:20 -0500 Subject: [PATCH 5/6] ignore estimability for R < 4.3.0 --- .github/workflows/R-CMD-check.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 74d8c97..34fccba 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -41,7 +41,9 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: any::rcmdcheck + extra-packages: | + any::rcmdcheck + estimability=?ignore-before-r=4.3.0 needs: check - uses: r-lib/actions/check-r-package@v2 From 5302ee78365d20fdd8cdad1976102d1eb66bc236 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Tue, 16 Apr 2024 01:00:55 -0500 Subject: [PATCH 6/6] I meant `emmeans` --- .github/workflows/R-CMD-check.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 34fccba..9107b77 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -43,7 +43,7 @@ jobs: with: extra-packages: | any::rcmdcheck - estimability=?ignore-before-r=4.3.0 + emmeans=?ignore-before-r=4.3.0 needs: check - uses: r-lib/actions/check-r-package@v2