-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43b9a94
commit d0f5c32
Showing
1 changed file
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
--- | ||
title: "Diff Tools" | ||
output: rmarkdown::html_vignette | ||
vignette: > | ||
%\VignetteIndexEntry{diff-tools} | ||
%\VignetteEngine{knitr::rmarkdown} | ||
%\VignetteEncoding{UTF-8} | ||
--- | ||
|
||
This vignette demonstrates using a variety of `diff-` functions to assist with | ||
QC efforts. All functions provide a visual difference of modifications to scripts. | ||
The functions covered below include: | ||
|
||
- `diffQced()` shows modifications to a script since it was last QCed. | ||
- `diffPreviousRevisions()` shows modifications between versions of the same script. | ||
- `diffFiles()` shows modifications between two scripts. | ||
|
||
# Load libraries | ||
|
||
```{r, message=FALSE} | ||
library(review) | ||
``` | ||
|
||
# Setup | ||
|
||
For the purposes of this vignette, a demo SVN repository and files were created | ||
using the `demoRepo()` function. The files in this repository are versioned | ||
and have past QC history. | ||
|
||
```{r} | ||
repo <- demoRepo("examp-123") | ||
``` | ||
|
||
# diffQced | ||
|
||
`diffQced()` generates a visual diff in the Viewer pane in R studio. | ||
All deleted, added and modified lines of code are shown in the diff. | ||
|
||
`diffQced()` uses the QC log to identify the revision number when the last QC | ||
was completed. The difference is then generated using the version of the file at | ||
that revision number versus the current file. | ||
|
||
For this example, we will look at the modifications made to `script/data-assembly.R` | ||
since its last QC. | ||
|
||
```{r eval=FALSE} | ||
diffQced("script/data-assembly.R") | ||
``` | ||
|
||
```{r echo=FALSE, message=FALSE, results='asis'} | ||
curdir <- getwd() | ||
on.exit(setwd(curdir)) | ||
setwd(repo) | ||
svnExport("script/data-assembly.R", 1) | ||
diffobj::diffFile( | ||
"data-assembly-1.R", | ||
"script/data-assembly.R", | ||
color.mode = "rgb", | ||
ignore.white.space = FALSE, | ||
mode = "sidebyside", | ||
tar.banner="Revision 1", | ||
cur.banner="Local", | ||
format = "html", | ||
style = list(html.output = "diff.w.style"), | ||
interactive = F | ||
) | ||
``` | ||
|
||
# diffPreviousRevisions | ||
|
||
`diffPreviousRevisions()` generates a similar visual, except the versions | ||
of the scripts being compared can be explicitly defined. | ||
|
||
For any script, a previous and current revision number can be set to decide | ||
the versions being used. If a current revision number is not provided, the | ||
default will be set to the most recent version of the script. | ||
|
||
For this example, we can use the `script/pk/load-spec.R` script. We can view | ||
the history of this file with `svnLog()`. | ||
|
||
```{r eval=FALSE} | ||
svnLog("script/pk/load-spec.R") | ||
``` | ||
|
||
```{r echo=FALSE} | ||
curdir <- getwd() | ||
on.exit(setwd(curdir)) | ||
setwd(repo) | ||
svnLog("script/pk/load-spec.R") | ||
``` | ||
|
||
Now using `diffPreviousRevisions()`, we can look at the differences between | ||
the file at revisions 1 and 4. | ||
|
||
```{r eval=FALSE} | ||
diffPreviousRevisions( | ||
.file = "script/pk/load-spec.R", | ||
.current_revision = 4, | ||
.previous_revision = 1) | ||
``` | ||
|
||
```{r echo=FALSE, message=FALSE, results='asis'} | ||
curdir <- getwd() | ||
on.exit(setwd(curdir)) | ||
setwd(repo) | ||
svnExport("script/pk/load-spec.R", 1) | ||
diffobj::diffFile( | ||
"load-spec-1.R", | ||
"script/pk/load-spec.R", | ||
color.mode = "rgb", | ||
ignore.white.space = FALSE, | ||
mode = "sidebyside", | ||
tar.banner="Revision 1", | ||
cur.banner="Local", | ||
format = "html", | ||
style = list(html.output = "diff.w.style"), | ||
interactive = F | ||
) | ||
``` | ||
|
||
# diffFiles | ||
|
||
`diffFiles()` generates a visual diff between two files. The first file | ||
provided will be treated as the past version when generating the visual diff. | ||
|
||
For this example, we can use the `script/combine-da.R` and | ||
`script/data-assembly.R` scripts. | ||
|
||
```{r eval=FALSE} | ||
diffFiles( | ||
.file_1 = "script/combine-da.R", | ||
.file_2 = "script/data-assembly.R" | ||
) | ||
``` | ||
|
||
```{r echo=FALSE, message=FALSE, results='asis'} | ||
curdir <- getwd() | ||
on.exit(setwd(curdir)) | ||
setwd(repo) | ||
diffobj::diffFile( | ||
"script/combine-da.R", | ||
"script/data-assembly.R", | ||
color.mode = "rgb", | ||
ignore.white.space = FALSE, | ||
mode = "sidebyside", | ||
tar.banner="Revision 1", | ||
cur.banner="Local", | ||
format = "html", | ||
style = list(html.output = "diff.w.style"), | ||
interactive = F | ||
) | ||
``` |