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

Compare individual strings #57

Open
hadley opened this issue Nov 29, 2020 · 4 comments
Open

Compare individual strings #57

hadley opened this issue Nov 29, 2020 · 4 comments
Labels
feature a feature request or enhancement

Comments

@hadley
Copy link
Member

hadley commented Nov 29, 2020

Making it easier to spot (e.g.) a non-breaking space vs. a space.

@hadley
Copy link
Member Author

hadley commented Dec 14, 2020

rvest is a common source of such confusion, e.g. tidyverse/rvest#284

@hadley hadley closed this as completed Dec 14, 2020
@hadley hadley reopened this Dec 14, 2020
@hadley
Copy link
Member Author

hadley commented Apr 28, 2021

Need to think about x <- c("\u00e1", "a\u0301")

And

cyrillic_a <- "А"
latin_a <- "A"
cyrillic_a == latin_a

@hadley
Copy link
Member Author

hadley commented Jul 18, 2021

Something like this:

compare_string <- function(x, y) {
  x_char <- strsplit(x, "")[[1]]
  y_char <- strsplit(y, "")[[1]]

  ses1 <- ses(x_char, y_char)
  if (nrow(ses1) == 0 || nrow(ses1) > length(x_char)) {
    return(list())
  }

  # If diff equivalent to every letter changing, don't highlight differences
  ses2 <- ses_elementwise(x_char, y_char)
  if (nrow(ses2) <= nrow(ses1)) {
    return(c(x, y))
  }

  diff <- ses1
  diff$x_start <- 1
  diff$x_end <- length(x)
  diff$y_start <- 1
  diff$y_end <- length(y)
  diff <- diff_complete(diff)

  aligned <- diff_align(diff, x, y)
  aligned$x[is.na(aligned$x)] <- " "
  aligned$y[is.na(aligned$y)] <- " "
  c(paste(aligned$x, collapse = ""), paste(aligned$y, collapse = ""))
}
  • Need to refactor diff_align() to make it easier to apply different formatting — don't style unchanged characters and highlight individual changes with background colours
  • Need option to apply in format_diff_matrix()? Can only be down after diff data is aligned.

@hadley hadley added the feature a feature request or enhancement label Mar 23, 2023
@hadley
Copy link
Member Author

hadley commented Aug 28, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant