Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Yihui Xie <xie@yihui.name>
  • Loading branch information
nanxstats and yihui committed May 28, 2024
1 parent eef2356 commit c78fd09
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,22 @@ update_unicode_latex <- function() {
"\\Micro", "\\times", "\\eth", "\\div", "\\bullet",
"\\vec", "\\eqcolon", "\\square", "\\blacksquare"
)), , drop = FALSE]
row.names(tbl) <- NULL

rows <- lapply(
seq_len(nrow(tbl)),
function(i) {
sprintf(
' c(unicode = "%s", latex = "%s", int = %d)',
tbl$unicode[i],
gsub("\\", "\\\\", tbl$latex[i], fixed = TRUE),
tbl$int[i]
)
}
rows <- paste(
tbl$unicode,
gsub("\\", "\\\\", tbl$latex, fixed = TRUE),
sprintf("%d", tbl$int),
sep = ", "
)

writeLines(c(
"# Generated by R/utils.R: do not edit by hand",
"# Please run update_unicode_latex() to regenerate this file",
"",
"unicode_latex <- data.frame(rbind(",
paste(rows, collapse = ",\n"),
"), stringsAsFactors = FALSE)",
"unicode_latex <- matrix(c(",
paste0(" ", rows, collapse = ",\n")
"), ncol = 3, byrow = TRUE)",
"unicode_latex <- as.data.frame(unicode_latex)",
'names(unicode_latex) <- c("unicode", "latex", "int")',
"",
"unicode_latex$int <- as.integer(unicode_latex$int)"
), con = "R/unicode_latex.R")
Expand Down

0 comments on commit c78fd09

Please sign in to comment.