Giter VIP home page Giter VIP logo

Comments (2)

elong0527 avatar elong0527 commented on August 15, 2024

Please try the code below for an ad-hoc solution. I will need to think a robust way to enable this feature in r2rtf.

If you still have issue, could you provide additional example using reprex? https://reprex.tidyverse.org/

the logic of convert_utf8 is from https://stackoverflow.com/questions/66275158/specify-utf-8-character-encoding-in-rtf-the-text-in-utf-8-format-is-correctly

#' Convert UTF text to proper RTF encoding 
#' 
#' @param x a string 
convert_utf8 <- function(x){

  stopifnot(length(x) == 1)
  
  x_int <- utf8ToInt(x)
  
  x_char <- ifelse(x_int < 32768, 
                   paste0("\\uc1\\u", x_int, "*"), 
                   paste0("\\uc1\\u", x_int - 65536, "*"))
  
  paste(x_char, collapse = "")
  
}

library(r2rtf)
library(dplyr)
head(iris) %>% 
  rtf_title(convert_utf8("标题: abc")) %>% 
  rtf_body() %>% 
  rtf_footnote(convert_utf8("脚注")) %>%
  rtf_encode() %>% 
  write_rtf("tmp.rtf")

from r2rtf.

elong0527 avatar elong0527 commented on August 15, 2024

Closing the issue.

With a recent fix in #93, we can use code below for the table.

library(r2rtf)
library(dplyr)
head(iris) %>% 
  rtf_title(r2rtf:::utf8Tortf("标题: abc")) %>% 
  rtf_body() %>% 
  rtf_footnote(r2rtf:::utf8Tortf("中文脚注: abc")) %>%
  rtf_encode() %>% 
  write_rtf("tmp.rtf")

from r2rtf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.