get_diff | R Documentation |
Any two revisions of a Wikipedia page can be compared using the 'diff' tool. The tool compares the 'from' revision to the 'to' revision, looking for insertions, deletions or relocations of text. This operation can be performed in any order, across any span of revisions.
get_diff(from, to, language = "en", simplify = TRUE)
from |
Vector of revision ids |
to |
Vector of revision ids |
language |
Vector of two-letter language codes (will be recycled if length==1) |
simplify |
logical: should R simplify the result (see return) |
The return value depends on the simplify
parameter.
If simplify
== TRUE: A list of tibble::tbl_df objects the same
length as from
and to
. Most of the response data is stripped away,
leaving just the textual differences between the revisions, their location,
type and 'highlightRanges' if the textual differences are complicated.
If simplify
== FALSE: A list the same length as from
and to
containing the full wikidiff2 response
for each pair of revisions. This response includes additional data for
displaying diffs onscreen.
# Compare revision 847170467 to 851733941 on English Wikipedia
get_diff(847170467, 851733941)
# The function is vectorised, so you can compare multiple pairs of revisions
# in a single call
# See diffs for the last two revisions of the Main Page
revisions <- wiki_action_request() %>%
query_by_title("Main Page") %>%
query_page_properties(
"revisions",
rvlimit = 2, rvprop = "ids", rvdir = "older"
) %>%
gracefully(next_result)
if (tibble::is_tibble(revisions)) {
revisions <- revisions %>%
tidyr::unnest(cols = c(revisions)) %>%
dplyr::mutate(diffs = get_diff(from = parentid, to = revid))
print(revisions)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.