Skip to content

Commit

Permalink
emulate POSIX defn of diff -b
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@62407 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
ripley committed Mar 26, 2013
1 parent bb63464 commit fcef74e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 4 additions & 0 deletions doc/NEWS.Rd
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@


\item \code{chooseCRANmirror()} and \code{chooseBioCmirror()} gain \item \code{chooseCRANmirror()} and \code{chooseBioCmirror()} gain
an \code{ind} argument (like \code{setRepositories()}). an \code{ind} argument (like \code{setRepositories()}).

\item \code{tools::Rdiff(useDiff = FALSE)} is closer to the POSIX
definition of \command{diff -b} (as distinct from the description
in the \command{man} pages of most systems).
} }
} }


Expand Down
8 changes: 6 additions & 2 deletions src/library/tools/R/testing.R
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -156,8 +156,12 @@ Rdiff <- function(from, to, useDiff = FALSE, forEx = FALSE, nullPointers=TRUE, L
right <- clean2(right) right <- clean2(right)
} }
if (!useDiff && (length(left) == length(right))) { if (!useDiff && (length(left) == length(right))) {
bleft <- gsub("[[:space:]]+", " ", left) ## The idea is to emulate diff -b, as documented by POSIX:
bright <- gsub("[[:space:]]+", " ", right) ## http://pubs.opengroup.org/onlinepubs/9699919799/utilities/diff.html
bleft <- gsub("[[:space:]]*$", "", left)
bright <- gsub("[[:space:]]*$", "", right)
bleft <- gsub("[[:space:]]+", " ", bleft)
bright <- gsub("[[:space:]]+", " ", bright)
if(all(bleft == bright)) if(all(bleft == bright))
return(if(Log) list(status = 0L, out = character()) else 0L) return(if(Log) list(status = 0L, out = character()) else 0L)
cat("\n") cat("\n")
Expand Down
13 changes: 7 additions & 6 deletions src/library/tools/man/Rdiff.Rd
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Rdiff(from, to, useDiff = FALSE, forEx = FALSE,
differences found?} differences found?}
} }
\details{ \details{

The \R startup banner and any timing information from \command{R CMD The \R startup banner and any timing information from \command{R CMD
BATCH} are removed from both files, together with lines about BATCH} are removed from both files, together with lines about
loading packages. UTF-8 fancy quotes (see \code{\link{sQuote}}) and loading packages. UTF-8 fancy quotes (see \code{\link{sQuote}}) and
Expand All @@ -35,12 +36,12 @@ Rdiff(from, to, useDiff = FALSE, forEx = FALSE,
(e.g. \code{<environment: 0x12345678>}) are mapped to (e.g. \code{<environment: 0x12345678>}) are mapped to
\code{0x00000000}. The files are then compared line-by-line. If \code{0x00000000}. The files are then compared line-by-line. If
there are the same number of lines and \code{useDiff} is false, a there are the same number of lines and \code{useDiff} is false, a
simple \command{diff}-like display of differences is printed (which simple \command{diff -b} -like display of differences is printed
ignores differences in consecutive spaces), otherwise \command{diff (which ignores trailing spaces and differences in numbers of
-bw} is called on the edited files. (This tries to ignore all consecutive spaces), otherwise \command{diff -bw} is called on the
differences in whitespace: note that flag \option{-w} is not edited files. (This tries to ignore all differences in whitespace:
required by POSIX but is supported by GNU, Solaris and FreeBSD note that flag \option{-w} is not required by POSIX but is supported
versions.) by GNU, Solaris and FreeBSD versions.)
This can compare uncompressed PDF files, ignoring differences in This can compare uncompressed PDF files, ignoring differences in
creation and modification dates. creation and modification dates.
Expand Down

0 comments on commit fcef74e

Please sign in to comment.