r-lib / prettycode

Syntax highlight R code in the terminal
https://r-lib.github.io/prettycode/
Other
101 stars 9 forks source link

Extra quote was outputted #18

Closed pwang2 closed 2 years ago

pwang2 commented 2 years ago

I was debugging a weird formatting issue here(https://github.com/r-lib/styler/issues/897), and the root cause was targeted to prettycode's replace_in_place function. Can you help diagnose why there is an extra quote before "An" was kept in the replace_in_place function?

> highlight(styler::style_text('a <- c( "TΔ", "An")'))
[1] "a \033[32m<-\033[39m \033[36mc\033[39m\033[33m(\033[39m\033[33m\"TΔ\"\033[39m,\"\033[33m\"An\"\033[39m\033[33m)\033[39m"

image

gaborcsardi commented 2 years ago

I cannot reproduce it on macOS, are you on a non-UTF8 locale? In general, it is best to only use ASCII characters in R code, in fact non-ASCII characters are even forbidden on CRAN.

pwang2 commented 2 years ago

I tried both C.UTF-8 and en_US.UTF-8 locales and got the same problem. I was able to reproduce on a new Ubuntu 18.04.6 LTS VM with new R installation 3.6.3. I am trying to provide a reproduce step with docker now.

pwang2 commented 2 years ago

I was able to reproduce using the following container.

docker run --rm -it r-base:3.6.3 R

# In container R repl
install.packages(c("styler", "prettycode"))

library(prettycode)
highlight(styler::style_text('a <- c( "TΔ", "An")'))
pwang2 commented 2 years ago

This might be helpful to investigate.

pwang2 commented 2 years ago

Any Update?

gaborcsardi commented 2 years ago

No, do not use non-ascii characters in code: https://github.com/r-lib/prettycode/issues/18#issuecomment-1007695821