This is a vignette to help you become familiar with using svnLog() and svnExport().

  • svnLog() provides the history of all edits made to a file, including the author, revision and date/time of the commit.
  • svnExport() makes it easy to restore a file to a previous revision.

Below we will go through examples of both, including cases where the information from svnLog() can be used to more efficiently use svnExport().

Load libraries

svnLog

For the purposes of this vignette, a demo SVN repository and files were created using the demoRepo() function. We will look at the history of script/data-assembly.R.

To figure out when modifications were made to this file, we can use svnLog().

repo <- demoRepo("examp-123")
svnLog(file.path(repo, "script/data-assembly.R"))
## # A tibble: 2 × 4
##   author   datetime            rev   msg                 
##   <chr>    <dttm>              <chr> <chr>               
## 1 michaelm 2024-06-04 21:04:52 5     modify data-assembly
## 2 michaelm 2024-06-04 21:04:52 1     initial commit

Notice how the output data.frame is sorted such that the most recent commit is shown on the first row. We can see every author and revision number where the file was modified and checked into SVN.

svnExport

Now that we know the revision numbers, we can use svnExport() to view any of the previous revisions. First we can look at what the current version of script/data-assembly.R looks like:

cat(readLines(file.path(repo, "script/data-assembly.R")), sep = "\n")
## library(tidyverse)
## source(here::here("script", "data-assembly", "da-functions.R"))
## src_abc <- mrgda::read_src_dir(here::here("data", "source", "STUDY-ABC"))
## derived <- list(sl = list(),tv = list())
## dm_0 <- src_abc$dm %>% filter(ACTARM != "Screen Failure")
## derived$sl$dm <- dm_0
## pk_0 <- src_abc$pc %>% filter(PCTEST == "TEST OF INTEREST")
## derived$tv$pc <- pk_0
## ex_1 <- src_abc$ex %>% filter(EXTRT == "DRUG OF INTEREST")
## derived$tv$dosing <- ex_1

Then, we can use svnExport() to view the first revision of the file.

svnExport(.file = file.path(repo, "script/data-assembly.R"), .revision = 1)

Notice how this creates a new file, data-assembly-1.R in the SVN directory.

file.exists(file.path(repo, "data-assembly-1.R"))
## [1] TRUE

Now we can take a look at the first revision of the file.

cat(readLines(file.path(repo, "data-assembly-1.R")), sep = "\n")
## library(tidyverse)
## src_abc <- mrgda::read_src_dir(here::here("data", "source", "STUDY-ABC"))
## derived <- list(sl = list(),tv = list())
## dm_0 <- src_abc$dm %>% filter(ACTARM != "Screen Failure")
## derived$sl$dm <- dm_0

This process can be done for any file that has been checked into your SVN repository. svnLog() can easily identify the revision numbers of past edits and svnExport() can restore the file with a file name following this syntax [{original file name}-{revision number}].