From a2d3851505b1263cb6702ee1d64ded13010631d4 Mon Sep 17 00:00:00 2001 From: Arni Magnusson Date: Mon, 6 Apr 2020 22:50:12 +0200 Subject: [PATCH] Add argument 'force' to clean(), clean.library(), and clean.software() --- NEWS | 4 ++++ R/clean.R | 17 ++++++++--------- R/clean.library.R | 6 ++++-- R/clean.software.R | 11 +++++++---- man/clean.Rd | 14 +++++++------- man/clean.library.Rd | 5 ++++- man/clean.software.Rd | 5 ++++- 7 files changed, 38 insertions(+), 24 deletions(-) diff --git a/NEWS b/NEWS index 324aa05..793890c 100644 --- a/NEWS +++ b/NEWS @@ -9,8 +9,12 @@ icesTAF 3.4-0 (2020-03-27) * Added function taf.session() to show session information. +* Added argument 'force' to clean(), clean.library(), and clean.software(). + * Added argument 'ignore' to cp(). +* Improved clean.software() to remove software folder, not just software files. + * Improved download.github() to store GitHub metadata in the DESCRIPTION file, if the GitHub resource is an R package. Warn if the tar.gz file looks like an R package nested inside a repository. diff --git a/R/clean.R b/R/clean.R index e1b1128..8c886e9 100644 --- a/R/clean.R +++ b/R/clean.R @@ -4,6 +4,8 @@ #' \verb{report}), \verb{bootstrap}, or other directories. #' #' @param dirs directories to delete. +#' @param force passed to \code{software} and \code{clean.library} if any of the +#' \code{dirs} is \code{"bootstrap"}. #' #' @note #' The purpose of removing the directories is to make sure that subsequent TAF @@ -17,16 +19,13 @@ #' \verb{bootstrap/initial} and \verb{*.bib} metadata files from being #' accidentally deleted. #' -#' The commands \code{clean("bootstrap/software")} and -#' \code{clean("bootstrap/library")} remove those directories completely. -#' #' @seealso -#' \code{\link{clean.library}} selectively removes packages from -#' \verb{bootstrap/library}. -#' #' \code{\link{clean.software}} selectively removes software from #' \verb{bootstrap/software}. #' +#' \code{\link{clean.library}} selectively removes packages from +#' \verb{bootstrap/library}. +#' #' \code{\link{mkdir}} and \code{\link{rmdir}} create and remove empty #' directories. #' @@ -39,7 +38,7 @@ #' #' @export -clean <- function(dirs=c("data", "model", "output", "report")) +clean <- function(dirs=c("data", "model", "output", "report"), force=FALSE) { ## Convert "bootstrap/" to "bootstrap", so clean("bootstrap/") doesn't go wild dirs <- sub("/$", "", dirs) @@ -48,8 +47,8 @@ clean <- function(dirs=c("data", "model", "output", "report")) { ## An odd directory called 'library:' can appear in Linux unlink(c("bootstrap/data", "bootstrap/library:"), recursive=TRUE) - clean.software("bootstrap/software") - clean.library("bootstrap/library") + clean.software("bootstrap/software", force=force) + clean.library("bootstrap/library", force=force) dirs <- dirs[dirs != "bootstrap"] } diff --git a/R/clean.library.R b/R/clean.library.R index fb8fc13..894968a 100644 --- a/R/clean.library.R +++ b/R/clean.library.R @@ -5,6 +5,8 @@ #' #' @param folder location of local TAF library. #' @param quiet whether to suppress messages about removed packages. +#' @param force whether to remove the local TAF library, regardless of how it +#' compares to SOFTWARE.bib entries. #' #' @note #' For each package, the cleaning procedure selects between three cases: @@ -39,11 +41,11 @@ #' #' @export -clean.library <- function(folder="bootstrap/library", quiet=FALSE) +clean.library <- function(folder="bootstrap/library", quiet=FALSE, force=FALSE) { installed <- dir(folder) - if(!file.exists(file.path(folder, "../SOFTWARE.bib"))) + if(!file.exists(file.path(folder, "../SOFTWARE.bib")) || force) { unlink(folder, recursive=TRUE) } diff --git a/R/clean.software.R b/R/clean.software.R index b461e10..45b853e 100644 --- a/R/clean.software.R +++ b/R/clean.software.R @@ -5,6 +5,8 @@ #' #' @param folder location of local TAF software folder. #' @param quiet whether to suppress messages about removed software. +#' @param force whether to remove the local TAF software folder, regardless of +#' how it compares to SOFTWARE.bib entries. #' #' @note #' For each file (and subdirectory) in the software folder, the cleaning @@ -39,11 +41,12 @@ #' #' @export -clean.software <- function(folder="bootstrap/software", quiet=FALSE) +clean.software <- function(folder="bootstrap/software", quiet=FALSE, + force=FALSE) { software.files <- dir(folder, full.names=TRUE) - if(!file.exists(file.path(folder, "../SOFTWARE.bib"))) + if(!file.exists(file.path(folder, "../SOFTWARE.bib")) || force) { unlink(folder, recursive=TRUE) } @@ -54,8 +57,8 @@ clean.software <- function(folder="bootstrap/software", quiet=FALSE) for(file in software.files) { ## Read sha.file, the SHA for a software file - pkg <- sub(".*/(.*)_.*", "\\1", file) # path/pkg_sha.tar.gz -> pkg - sha.file <- sub(".*_(.*?)\\..*", "\\1", file) # path/pkg_sha.tar.gz -> sha + pkg <- sub(".*/(.*)_.*", "\\1", file) # path/pkg_sha.tar.gz -> pkg + sha.file <- sub(".*_(.*?)\\..*", "\\1", file) # path/pkg_sha.tar.gz -> sha ## Read sha.bib, the corresponding SHA from SOFTWARE.bib if(pkg %in% names(bib)) { diff --git a/man/clean.Rd b/man/clean.Rd index e66ca17..6e60355 100644 --- a/man/clean.Rd +++ b/man/clean.Rd @@ -4,10 +4,13 @@ \alias{clean} \title{Clean TAF Directories} \usage{ -clean(dirs = c("data", "model", "output", "report")) +clean(dirs = c("data", "model", "output", "report"), force = FALSE) } \arguments{ \item{dirs}{directories to delete.} + +\item{force}{passed to \code{software} and \code{clean.library} if any of the +\code{dirs} is \code{"bootstrap"}.} } \description{ Remove working TAF directories (\verb{data}, \verb{model}, \verb{output}, @@ -24,9 +27,6 @@ subdirectories \verb{data} is removed, while \code{clean.software} and \verb{bootstrap/library} subdirectories. This protects the subdirectory \verb{bootstrap/initial} and \verb{*.bib} metadata files from being accidentally deleted. - -The commands \code{clean("bootstrap/software")} and -\code{clean("bootstrap/library")} remove those directories completely. } \examples{ \dontrun{ @@ -35,12 +35,12 @@ clean() } \seealso{ -\code{\link{clean.library}} selectively removes packages from -\verb{bootstrap/library}. - \code{\link{clean.software}} selectively removes software from \verb{bootstrap/software}. +\code{\link{clean.library}} selectively removes packages from +\verb{bootstrap/library}. + \code{\link{mkdir}} and \code{\link{rmdir}} create and remove empty directories. diff --git a/man/clean.library.Rd b/man/clean.library.Rd index 7e1b6b1..975ec28 100644 --- a/man/clean.library.Rd +++ b/man/clean.library.Rd @@ -4,12 +4,15 @@ \alias{clean.library} \title{Clean TAF Library} \usage{ -clean.library(folder = "bootstrap/library", quiet = FALSE) +clean.library(folder = "bootstrap/library", quiet = FALSE, force = FALSE) } \arguments{ \item{folder}{location of local TAF library.} \item{quiet}{whether to suppress messages about removed packages.} + +\item{force}{whether to remove the local TAF library, regardless of how it +compares to SOFTWARE.bib entries.} } \description{ Selectively remove packages from the local TAF library if not listed in diff --git a/man/clean.software.Rd b/man/clean.software.Rd index d4ada6b..1a4df0e 100644 --- a/man/clean.software.Rd +++ b/man/clean.software.Rd @@ -4,12 +4,15 @@ \alias{clean.software} \title{Clean TAF Software} \usage{ -clean.software(folder = "bootstrap/software", quiet = FALSE) +clean.software(folder = "bootstrap/software", quiet = FALSE, force = FALSE) } \arguments{ \item{folder}{location of local TAF software folder.} \item{quiet}{whether to suppress messages about removed software.} + +\item{force}{whether to remove the local TAF software folder, regardless of +how it compares to SOFTWARE.bib entries.} } \description{ Selectively remove software from the local TAF software folder if not listed