Skip to content
Browse files

emulate POSIX defn of diff -b

git-svn-id: https://svn.r-project.org/R/trunk@62407 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information...
1 parent bb63464 commit fcef74e0274649ca853396e90e5f07f81f4ed30b ripley committed Mar 26, 2013
Showing with 17 additions and 8 deletions.
  1. +4 −0 doc/NEWS.Rd
  2. +6 −2 src/library/tools/R/testing.R
  3. +7 −6 src/library/tools/man/Rdiff.Rd
View
4 doc/NEWS.Rd
@@ -32,6 +32,10 @@
\item \code{chooseCRANmirror()} and \code{chooseBioCmirror()} gain
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).
}
}
View
8 src/library/tools/R/testing.R
@@ -156,8 +156,12 @@ Rdiff <- function(from, to, useDiff = FALSE, forEx = FALSE, nullPointers=TRUE, L
right <- clean2(right)
}
if (!useDiff && (length(left) == length(right))) {
- bleft <- gsub("[[:space:]]+", " ", left)
- bright <- gsub("[[:space:]]+", " ", right)
+ ## The idea is to emulate diff -b, as documented by POSIX:
+ ## 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))
return(if(Log) list(status = 0L, out = character()) else 0L)
cat("\n")
View
13 src/library/tools/man/Rdiff.Rd
@@ -26,6 +26,7 @@ Rdiff(from, to, useDiff = FALSE, forEx = FALSE,
differences found?}
}
\details{
+
The \R startup banner and any timing information from \command{R CMD
BATCH} are removed from both files, together with lines about
loading packages. UTF-8 fancy quotes (see \code{\link{sQuote}}) and
@@ -35,12 +36,12 @@ Rdiff(from, to, useDiff = FALSE, forEx = FALSE,
(e.g. \code{<environment: 0x12345678>}) are mapped to
\code{0x00000000}. The files are then compared line-by-line. If
there are the same number of lines and \code{useDiff} is false, a
- simple \command{diff}-like display of differences is printed (which
- ignores differences in consecutive spaces), otherwise \command{diff
- -bw} is called on the edited files. (This tries to ignore all
- differences in whitespace: note that flag \option{-w} is not
- required by POSIX but is supported by GNU, Solaris and FreeBSD
- versions.)
+ simple \command{diff -b} -like display of differences is printed
+ (which ignores trailing spaces and differences in numbers of
+ consecutive spaces), otherwise \command{diff -bw} is called on the
+ edited files. (This tries to ignore all differences in whitespace:
+ note that flag \option{-w} is not required by POSIX but is supported
+ by GNU, Solaris and FreeBSD versions.)
This can compare uncompressed PDF files, ignoring differences in
creation and modification dates.

0 comments on commit fcef74e

Please sign in to comment.
Something went wrong with that request. Please try again.