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.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.
repo <- demoRepo("examp-123")
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.
diffQced("script/data-assembly.R")
@@ 1,5 @@@@ 1,10 @@library(tidyverse)library(tidyverse)~>source(here::here("script", "data-assembly", "da-functions.R"))src_abc <- mrgda::read_src_dir(here::here("data", "source", "STUDY-ABC"))src_abc <- mrgda::read_src_dir(here::here("data", "source", "STUDY-ABC"))derived <- list(sl = list(),tv = list())derived <- list(sl = list(),tv = list())dm_0 <- src_abc$dm %>% filter(ACTARM != "Screen Failure")dm_0 <- src_abc$dm %>% filter(ACTARM != "Screen Failure")derived$sl$dm <- dm_0derived$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
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()
.
svnLog("script/pk/load-spec.R")
## # A tibble: 2 × 4
## author datetime rev msg
## <chr> <dttm> <chr> <chr>
## 1 michaelm 2024-11-14 20:31:34 4 modify load-spec script
## 2 michaelm 2024-11-14 20:31:34 1 initial commit
Now using diffPreviousRevisions()
, we can look at the
differences between the file at revisions 1 and 4.
diffPreviousRevisions(
.file = "script/pk/load-spec.R",
.current_revision = 4,
.previous_revision = 1)
@@ 1 @@@@ 1 @@<pk_spec <- yspec::load_spec(here::here("script", "script/examp-yaml.yaml"))>pk_spec <- yspec::load_spec(here::here("script", "examp-yaml.yaml"))
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.
diffFiles(
.file_1 = "script/combine-da.R",
.file_2 = "script/data-assembly.R"
)
@@ 1,6 @@@@ 1,10 @@library(tidyverse)library(tidyverse)<studies <- list()>source(here::here("script", "data-assembly", "da-functions.R"))<studies$pk_abc <- readr::read_rds(here::here("data", "derived", "studies", "pk-abc.rds"))>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 <- bind_rows(studies) %>% arrange(USUBJID, DATETIME)>pk_0 <- src_abc$pc %>% filter(PCTEST == "TEST OF INTEREST")<pk_1 <- pk_0 %>% mrgda::assign_id(., "USUBJID")>derived$tv$pc <- pk_0<pk_out <- pk_1>ex_1 <- src_abc$ex %>% filter(EXTRT == "DRUG OF INTEREST")~>derived$tv$dosing <- ex_1