This function produces a LaTeX mark up that highlights text differences between two input sentences.

compare_sentences(
  sentence1,
  sentence2,
  highlight_diff = "underline",
  NA.string = c("n/a", "na", "N/A", "NA", "Not applicable", "not applicable",
    "Not Applicable")
)

Arguments

sentence1

Original text

sentence2

Revised text

highlight_diff

Font type used to highlight text differences. Defaults to underline. Other options are bold, italics, and standard.

NA.string

String defining characters recognised as "NA".

Value

A LaTeX formatted string showing text differences when rendered.

Examples

library(respondR) library(tidyverse)
#> ── Attaching packages ────────────────────────────────────────────────────── tidyverse 1.3.0 ──
#> ggplot2 3.3.2 purrr 0.3.4 #> tibble 3.0.4 dplyr 1.0.2 #> tidyr 1.1.2 stringr 1.4.0 #> readr 1.4.0 forcats 0.5.0
#> ── Conflicts ───────────────────────────────────────────────────────── tidyverse_conflicts() ── #> x dplyr::filter() masks stats::filter() #> x dplyr::lag() masks stats::lag()
compare_sentences(sentence1 = "My name is Patricia.", sentence2 = "My name is Stacey.", highlight_diff = "underline", NA.string = c("n/a", "na", "N/A", "NA"))
#> [1] "My name is \\uline{Stacey}."
compare_sentences(sentence1 = "The sky is blue and the grass is green.", sentence2 = "The ocean is blue and the apples are green!", highlight_diff = "underline", NA.string = c("n/a", "na", "N/A", "NA", "Not applicable", "not applicable", "Not Applicable"))
#> [1] "The \\uline{ocean} is blue and the \\uline{...} \\uline{apples are} green \\uline{!}"
compare_sentences(sentence1 = "My tailor is rich, and those flowers are beautiful!", sentence2 = "Their tailor is very wealthy, and these flowers are beautiful!", highlight_diff = "underline", NA.string = c("n/a", "na", "N/A", "NA"))
#> [1] "\\uline{Their} tailor is \\uline{very wealthy}, and \\uline{these} flowers are beautiful!"