[R] Python difflib R equivalent?
Prof Brian Ripley
ripley at stats.ox.ac.uk
Thu Jul 28 18:15:23 CEST 2011
On Thu, 28 Jul 2011, Bert Gunter wrote:
> 1. I do not know if any such library exists.
Not to my knowledge, and we have contemplated providing such
functions. But for files see e.g. tools::Rdiff, and generally R will
not be a good way to do this sort of thing on files (since the
flexibility of R's i/o via connections does have a cost)
> 2. However, if I understand correctly, one usually does this sort of
> thing in R with functions like ?match (or ?"%in%") and logical
> comparison operations like ?"==" . Of course, for numeric
> comparisons, you need to be aware of R FAQ 7.31
> If you are interested in comparing what in R are character vectors,
> then various string operators, e.g. ?grep, ?regexp and character
> operation packages (e.g. gsubfn, stringr) may be of use.
> As usual, you are more likely to receive a helpful answer if you do as
> the posting guide requests and provide a small, reproducible example
> of the sort(s) of thing(s) you want to do.
Or at least a URI of examples you wish to emulate, which for difflib
seem to be the sort of thing POSIX diff and friends are used for.
> On Thu, Jul 28, 2011 at 4:05 AM, Paul <newzealandspaul at gmail.com> wrote:
>> Does anyone know of a R library that is equivalent in functionality to
>> the Python standard libraries' difflib library? The python docs say
>> this about difflib:
>> "This module provides classes and functions for comparing sequences.
>> It can be used for example, for comparing files, and can produce
>> difference information in various formats, including HTML and context
>> and unified diffs."
>> R-help at r-project.org mailing list
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> "Men by nature long to get on to the ultimate truths, and will often
> be impatient with elementary studies or fight shy of them. If it were
> possible to reach the ultimate truths without the elementary studies
> usually prefixed to them, these would not be preparatory studies but
> superfluous diversions."
> -- Maimonides (1135-1204)
> Bert Gunter
> Genentech Nonclinical Biostatistics
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help