Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Generated by roxygen2: do not edit by hand

export(demoRepo)
export(demoRepoGit)
export(demoRepoSVN)
export(diffQced)
export(gitLog)
export(logAccept)
export(logAssign)
export(logCreate)
export(logPending)
export(logSummary)
export(with_demoRepo)
export(vcsLastCommit)
export(with_demoRepoGit)
export(with_demoRepoSVN)
51 changes: 51 additions & 0 deletions R/demoRepo-content.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#' @keywords internal
demoRepo_content1 <- function() {
writeLines("Version: 1.0", con = "temp.Rproj")

# Add scripts to the repo
fs::dir_create("script/pk", recurse = TRUE)
fs::dir_create("deliv/figure")
fs::dir_create("deliv/table")

writeLines(
c(
"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"
),
"script/data-assembly.R"
)

writeLines(
c(
"library(tidyverse)",
"studies <- list()",
'studies$pk_abc <- readr::read_rds(here::here("data", "derived", "studies", "pk-abc.rds"))',
"pk_0 <- bind_rows(studies) %>% arrange(USUBJID, DATETIME)",
'pk_1 <- pk_0 %>% mrgda::assign_id(., "USUBJID")',
"pk_out <- pk_1"
),
"script/combine-da.R"
)

writeLines(
c(
'pk_spec <- yspec::load_spec(here::here("script", "script/examp-yaml.yaml"))'
),
"script/pk/load-spec.R"
)

writeLines(c('This is the first version of the txt file'),
"script/examp-txt.txt")

writeLines(c("This is the first version of the yaml file"),
"script/examp-yaml.yaml")

writeLines(c("This is the first version of the yml file"),
"pkgr.yml")

# Create QC log
logCreate()
}
54 changes: 6 additions & 48 deletions R/demoRepo.R → R/demoRepoGit.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
#'
#' @param clean Logical indicating if the temporary directory should be deleted after use
#'
#' @usage demoRepo(clean = TRUE)
#' @usage demoRepoGit(clean = TRUE)
#'
#' @export
demoRepo <- function(clean = TRUE) {
demoRepoGit <- function(clean = TRUE) {

repoInitPath <- withr::local_tempdir(
"qctools-demo-",
Expand All @@ -28,49 +28,7 @@ demoRepo <- function(clean = TRUE) {

withr::local_dir(repoInitPath)

writeLines("Version: 1.0", con = "temp.Rproj")

# Add scripts to the repo
fs::dir_create("script/pk", recurse = TRUE)

writeLines(
c(
"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"
),
"script/data-assembly.R"
)

writeLines(
c(
"library(tidyverse)",
"studies <- list()",
'studies$pk_abc <- readr::read_rds(here::here("data", "derived", "studies", "pk-abc.rds"))',
"pk_0 <- bind_rows(studies) %>% arrange(USUBJID, DATETIME)",
'pk_1 <- pk_0 %>% mrgda::assign_id(., "USUBJID")',
"pk_out <- pk_1"
),
"script/combine-da.R"
)

writeLines(
c(
'pk_spec <- yspec::load_spec(here::here("script", "script/examp-yaml.yaml"))'
),
"script/pk/load-spec.R"
)

writeLines(c('This is the first version of the txt file'),
"script/examp-txt.txt")

writeLines(c("This is the first version of the yaml file"),
"script/examp-yaml.yaml")

# Create QC log
logCreate()
demoRepo_content1()

processx::run("git", c("add", "."))
processx::run("git", c("commit", "-m", "'initial commit'", "--quiet"))
Expand Down Expand Up @@ -133,11 +91,11 @@ demoRepo <- function(clean = TRUE) {
repoInitPath
}

#' @rdname demoRepo
#' @rdname demoRepoGit
#'
#' @param code Executable code to run
#' @export
with_demoRepo <- function(code, clean = TRUE) {
repo <- demoRepo(clean)
with_demoRepoGit <- function(code, clean = TRUE) {
repo <- demoRepoGit(clean)
withr::with_dir(repo, code)
}
105 changes: 105 additions & 0 deletions R/demoRepoSVN.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#' Create Demo SVN Repo
#'
#' @description
#' Create a SVN repo with files checked in and a QC log. The purpose of this
#' demo repo is for the user to become familiar with using review functions.
#'
#' The files checked into the repo are at various stages in terms of their QC
#' status. This function returns the path to the repo, so that the user can set
#' their working directory to it.
#'
#' This demo repo is created under the R session `/tmp/` directory, so a new one
#' will need to be generated whenever the user restarts R.
#'
#' @param clean Logical indicating if the temporary directory should be deleted after use
#'
#' @usage demoRepoSVN(clean = TRUE)
#'
#' @export
demoRepoSVN <- function(clean = TRUE) {

repoInitPath <- withr::local_tempdir(
"qctools-demo-svn-",
clean = clean,
.local_envir = parent.frame()
)

processx::run("svnadmin", c("create", repoInitPath))
repoDir <- file.path(repoInitPath, "svn-proj-123")

processx::run("svn", c("co", paste0("file://", repoInitPath), repoDir, "-q"))

withr::local_dir(repoDir)

demoRepo_content1()

# Check everything into SVN
processx::run("svn", c("add", "--force", "."))
processx::run("svn", c("commit", "-m", "'initial commit'", "-q", "-q"))

logAssign("script/data-assembly.R")
logAssign("script/pk/load-spec.R")
logAssign("script/combine-da.R")
logAssign("script/examp-txt.txt")

processx::run("svn", c("add", "--force", "."))
processx::run("svn", c("commit", "-m", "'logAssign scripts ready for QC'", "-q", "-q"))

logAccept("script/data-assembly.R")
logAccept("script/pk/load-spec.R")
logAccept("script/combine-da.R")

# Check in updates to QC log
processx::run("svn", c("add", "--force", "."))
processx::run("svn", c("commit", "-m", "'logAccept scripts ready for QC'", "-q", "-q"))

# Make edits to QCed file
writeLines(
c('pk_spec <- yspec::load_spec(here::here("script", "examp-yaml.yaml"))'),
"script/pk/load-spec.R"
)

processx::run("svn", c("add", "--force", "."))
processx::run("svn", c("commit", "-m", "'modify load-spec script'", "-q", "-q"))

writeLines(
c(
"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"
),
"script/data-assembly.R"
)

processx::run("svn", c("add", "--force", "."))
processx::run("svn", c("commit", "-m", "'modify data-assembly'", "-q", "-q"))

writeLines(
c("The following tasks are suggested to gain familiarity with the review package:",
'- run `diffQced()` on "script/pk/load-spec.R" and "script/data-assembly.R"',
'- run `renderQCSummary()`',
'- use `logAssign()` to add "script/examp-txt.txt" to the QC log',
'- run `logPending()` to see what scripts are in need of QC',
'- use `logAccept()` to sign off on any scripts with pending QC'),
"README.md"
)

repoDir

}

#' @rdname demoRepoSVN
#'
#' @param code Executable code to run
#' @export
with_demoRepoSVN <- function(code, clean = TRUE) {
repo <- demoRepoSVN(clean)
withr::with_dir(repo, code)
}
27 changes: 13 additions & 14 deletions R/diffQced.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
#' @param file file path from working directory
#'
#' @examples
#' with_demoRepo({
#' with_demoRepoGit({
#' diffQced("script/data-assembly.R")
#' })
#'
#' @export
diffQced <- function(file) {

vcs <- get_vcs()

# Modify file to correct path format
file_abs <- fs::path_abs(path = file)

Expand All @@ -32,28 +34,25 @@ diffQced <- function(file) {
if (length(log_file) == 0) {
stop(paste0(file, " not in QC log"), call. = FALSE)
}
version_new <- gitLog(file)[["last_commit"]]

version_new <- vcsLastCommit(file)[["last_commit"]]
version_qc <- log_file[length(log_file)]

if (version_new == version_qc) {
stop("File is up to date with QC", call. = FALSE)
}

# Prepend "./" so that 'git cat-file' interprets the path relative to the
# working directory rather than the top-level directory of the Git repo.
commit_file_new <- paste0(version_new, ":./", file_rel)
commit_file_qc <- paste0(version_qc, ":./", file_rel)

tempfile_new <- file.path(tempdir(), paste0("new-", basename(file_rel)))
tempfile_qc <- file.path(tempdir(), paste0("qced-", basename(file_rel)))

processx::run(
"git", c("cat-file", "blob", commit_file_new),
stdout = tempfile_new, wd = logDir())
processx::run(
"git", c("cat-file", "blob", commit_file_qc),
stdout = tempfile_qc, wd = logDir())
vcsExport(
.file = file_rel,
.vcs = vcs,
.version_new = version_new,
.version_qc = version_qc,
.temp_new = tempfile_new,
.temp_qc = tempfile_qc
)

diffobj::diffFile(
target = tempfile_qc,
Expand Down
22 changes: 22 additions & 0 deletions R/get-vcs.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#' @keywords internal
get_vcs <- function() {

svnCheck <- tryCatch(processx::run("svn", c("info"),
wd = logDir(),
error_on_status = FALSE))

if (svnCheck$status == 0) {
return("svn")
}

gitCheck <- tryCatch(processx::run("git", c("log"),
wd = logDir(),
error_on_status = FALSE))

if (gitCheck$status == 0) {
return("git")
}

stop(logDir(), " is not a git or svn repository")

}
6 changes: 3 additions & 3 deletions R/logAccept.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
#' @param file character file path (either the absolute or relative file path from the QC log)
#'
#' @examples
#' with_demoRepo({
#' with_demoRepoGit({
#' logAccept(file = "script/data-assembly.R")
#' })
#'
#' @export
logAccept <- function(file){

git_commit <- gitLog(file)
version <- vcsLastCommit(file)

logEdit(
.file = file,
.reviewer = Sys.info()[["user"]],
.commit = git_commit$last_commit
.commit = version$last_commit
)

}
2 changes: 1 addition & 1 deletion R/logAssign.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' @param reviewer specify a specific person to review the file (defaults to "anyone")
#'
#' @examples
#' with_demoRepo({
#' with_demoRepoGit({
#' logAssign(
#' file = "script/examp-yaml.yaml",
#' reviewer = "person1")
Expand Down
2 changes: 1 addition & 1 deletion R/logCreate.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' created in the directory where the RStudio project file (`*.Rproj`) exists.
#'
#' @examples
#' with_demoRepo({
#' with_demoRepoGit({
#' file.remove("QClog.csv")
#' logCreate()
#' })
Expand Down
Loading