Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally wrap text in bidi isolates and overrides #333

Closed
krlmlr opened this issue Jul 20, 2021 · 4 comments · Fixed by #350
Closed

Optionally wrap text in bidi isolates and overrides #333

krlmlr opened this issue Jul 20, 2021 · 4 comments · Fixed by #350
Milestone

Comments

@krlmlr
Copy link
Member

krlmlr commented Jul 20, 2021

for better support of RTL languages.

Should be a default in the next minor/major release.

CC @isteves @adisarid.

# Reference: https://www.w3.org/International/questions/qa-bidi-unicode-controls
fsi <- function(...) paste0("\u2068", ..., "\u2069")
# lri <- function(...) paste0("\u2066", ..., "\u2069")
# rli <- function(...) paste0("\u2067", ..., "\u2069")
lro <- function(...) paste0("\u202d", ..., "\u202c")

aleph <- "א"
bet <- "ב"

# Text output is right-to-left...
paste0(aleph, bet)
#> [1] "אב"

# but we can force the components to be left to right
writeLines(lro(paste0(
  fsi(aleph, bet),
  " ",
  fsi(bet, aleph)
)))
#> ‭⁨אב⁩ ⁨בא⁩‬

Created on 2021-04-16 by the reprex package (v1.0.0)

@krlmlr
Copy link
Member Author

krlmlr commented Jul 26, 2021

Reprex:

aleph <- "א"
bet <- "ב"

data <- as.list(1:2)
names(data) <- c(aleph, bet)
pillar:::new_tbl(data)
#> # A data frame: 1 × 2
#>       א     ב
#>   <int> <int>
#> 1     1     2

Created on 2021-07-26 by the reprex package (v2.0.0.9000)

@krlmlr
Copy link
Member Author

krlmlr commented Jul 26, 2021

With FSI and LRO:

aleph <- "א"
bet <- "ב"

data <- as.list(1:2)
names(data) <- c(aleph, bet)
pillar:::new_tbl(data)
#> # A data frame: 1 × 2
#> ‭⁨ ⁩ ⁨    א⁩ ⁨    ב⁩‬
#> ‭⁨ ⁩ ⁨<int>⁩ ⁨<int>⁩‬
#> ‭⁨1⁩ ⁨    1⁩ ⁨    2⁩‬

Created on 2021-07-26 by the reprex package (v2.0.0.9000)

Also works in RStudio (at least on my Mac) 🎉

Needs #339 (for the option).

@krlmlr krlmlr mentioned this issue Jul 26, 2021
@krlmlr
Copy link
Member Author

krlmlr commented Jul 27, 2021

Now exposed through the pillar.bidi option.

aleph <- "א"
bet <- "ב"

data <- as.list(1:2)
names(data) <- c(aleph, bet)
pillar:::new_tbl(data)
#> # A data frame: 1 × 2
#>       א     ב
#>   <int> <int>
#> 1     1     2

options(pillar.bidi = TRUE)
pillar:::new_tbl(data)
#> # A data frame: 1 × 2
#> ‭⁨ ⁩ ⁨    א⁩ ⁨    ב⁩‬
#> ‭⁨ ⁩ ⁨<int>⁩ ⁨<int>⁩‬
#> ‭⁨1⁩ ⁨    1⁩ ⁨    2⁩‬

Created on 2021-07-27 by the reprex package (v2.0.0.9000)

It will be more difficult to take directionality into account for deciding if the column title should be left- or right-aligned. We could solve this in {utf8} if needed, please file an issue there. (We'd likely use a new justify option "bidi" or such.)

aleph <- "א"
utf8::utf8_format(aleph, width = 5, justify = "left")
#> [1] "א    "

Created on 2021-07-27 by the reprex package (v2.0.0.9000)

krlmlr added a commit that referenced this issue Jul 27, 2021
- New `pillar.bidi` option. When active, control characters are inserted to improve display of data with right-to-left text (#333).
@github-actions
Copy link
Contributor

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant