-
Notifications
You must be signed in to change notification settings - Fork 6
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
Protect against escapes in strings #12
Comments
Some reprex material: foo <- "23\xbfC"
crayon::col_nchar(foo)
Encoding(foo) <- "latin1"
crayon::col_nchar(foo)
df <- data.frame(
bad = "23\xbfC"
)
paint(df)
Encoding(df$bad) <- "latin1" Idea: option to set a default encoding to be used in the event of an |
From Dan Wilson, I think these two together might solve the problem library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
df <- data.frame(
bad = "23\xbfC"
)
df %>%
mutate(
good = case_when(
!validEnc(bad) ~ stringi::stri_trans_general(bad, "latin-ascii")
)
) %>%
select(good) %>%
paint::paint()
#> data.frame [1, 1]
#> good chr 23�C Created on 2022-10-04 with reprex v2.0.2 |
The other aspect to think about might be how to identify data that has been transformed to allow printing. Maybe invert background/foreground colours? |
I like this idea @danwwilson! |
Just hit this one "2015 President and Vice-Chancellor\x92s Alumni Scholarship Appeal" 🤪 |
another option is to try
|
I saw a string with this sequence crash paint:
23\xbfC
The text was updated successfully, but these errors were encountered: