Gt: `as_rtf()` not handling ampersand

Created on 26 Oct 2020  Â·  4Comments  Â·  Source: rstudio/gt

as_rtf() is not handling ampersands correctly. Could be example of a bigger issue. reprex shows standard gt() example written to rtf. Then rtf output as shown in Microsoft Word 2016.

# as_rtf_err.R
# Example using as_rtf() to illustrate a bug
library(gt)
library(tidyverse)
library(glue)

# Define the start and end dates for the data range
start_date <- "2010-06-07"
end_date <- "2010-06-14"

# Create a gt table based on preprocessed
# `sp500` table data
gtTable <- sp500 %>%
  dplyr::filter(date >= start_date & date <= end_date) %>%
  dplyr::select(-adj_close) %>%
  gt() %>%
  tab_header(
    title = "S&P 500",
    subtitle = glue::glue("{start_date} to {end_date}")
  ) %>%
  fmt_date(
    columns = vars(date),
    date_style = 3
  ) %>%
  fmt_currency(
    columns = vars(open, high, low, close),
    currency = "USD"
  ) %>%
  fmt_number(
    columns = vars(volume),
    suffixing = TRUE
  )
gtTable %>% as_rtf() %>% write_lines("RTF with error.rtf")

S&P 500

2010-06-07 to 2010-06-14
date | open | high | low | close | volume
Mon, Jun 14, 2010
$1,095.00 | $1,105.91 | $1,089.03 | $1,089.63 | 4.43B
Fri, Jun 11, 2010
$1,082.65 | $1,092.25 | $1,077.12 | $1,091.60 | 4.06B
Thu, Jun 10, 2010
$1,058.77 | $1,087.85 | $1,058.77 | $1,086.84 | 5.14B
Wed, Jun 9, 2010
$1,062.75 | $1,077.74 | $1,052.25 | $1,055.69 | 5.98B
Tue, Jun 8, 2010
$1,050.81 | $1,063.15 | $1,042.17 | $1,062.00 | 6.19B
Mon, Jun 7, 2010
$1,065.84 | $1,071.36 | $1,049.86 | $1,050.47 | 5.47B

RTF with error.docx

[2] Intermediate [2] Medium ♨︎ Critical ☹︎ Bug

All 4 comments

Thank you for submitting this issue! We will fix this ASAP.

Hi @rich-iannone. Similar issue with less than/greater than signs (< and > are output as &lt; and &gt;). Please let me know if I should submit a separate issue for that.

@DickStartz when I tried the code on my system, the RTF file generated a table without issues. Here is a screenshot:

as_rtf

I suppose the issue was resolved some time after you reported it.

@parmsam I tried using < and > and encountered no problems with that in the output RTF files (opening in Word didn't show HTML entities).

Because everything's looking good, I'll close this one.

I confirm that it works in R 4.1.0 using RStudio 1.4.1106 on Windows 10.

Thanks for looking into this.

-Dick

Dick Startz

@.*

http://startz.weebly.com/

Dept. of Economics

University of California

Santa Barbara, CA 93106-9210

From: Richard Iannone @.>
*Sent:
Wednesday, June 30, 2021 8:53 AM
To: rstudio/gt
@.>
*Cc:
DickStartz @.>; Mention *@.>
*Subject:
Re: [rstudio/gt] as_rtf() not handling ampersand (#668)

@DickStartz https://github.com/DickStartz when I tried the code on my
system, the RTF file generated a table without issues. Here is a screenshot:

[image: as_rtf]
https://user-images.githubusercontent.com/5612024/123992162-5d17da00-d999-11eb-9bb1-b3a4eb3d2b41.png

I suppose the issue was resolved some time after you reported it.

@parmsam https://github.com/parmsam I tried using < and > and encountered
no problems with that in the output RTF files (opening in Word didn't show
HTML entities).

Because everything's looking good, I'll close this one.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/rstudio/gt/issues/668#issuecomment-871523626, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AQBNQCKD7LTK2UTY5OTN2ILTVM4W7ANCNFSM4S72MTOA
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vincentarelbundock picture vincentarelbundock  Â·  4Comments

rich-iannone picture rich-iannone  Â·  4Comments

mine-cetinkaya-rundel picture mine-cetinkaya-rundel  Â·  4Comments

TuSKan picture TuSKan  Â·  6Comments

jenniferp96 picture jenniferp96  Â·  4Comments