From aa497678fb459a2c7f63a3354dc3d3ed42127a3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Biecek?= Date: Sat, 25 Nov 2017 00:37:14 +0100 Subject: [PATCH] fixes for #298 --- NAMESPACE | 2 ++ NEWS.md | 1 + R/aread.R | 35 +++++++++++++++++++++++ R/asearch.R | 42 +++++++++++++++++++++++++++ man/areadLocal.Rd | 63 ++++++++++++++++++++++++++++++++++++++++ man/asearchLocal.Rd | 70 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 213 insertions(+) create mode 100644 man/areadLocal.Rd create mode 100644 man/asearchLocal.Rd diff --git a/NAMESPACE b/NAMESPACE index 09f9b95..1c75cac 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -13,8 +13,10 @@ export(ahistory) export(alink) export(aoptions) export(aread) +export(areadLocal) export(asave) export(asearch) +export(asearchLocal) export(asession) export(atrace) export(cache) diff --git a/NEWS.md b/NEWS.md index 57b2b92..777426c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ archivist 2.2 ---------------------------------------------------------------- +* Two new functions `asearchLocal()` and `areadLocal()` that work as `asearch()` and `aread()` for selected local repositories ([#298](https://github.com/pbiecek/archivist/issues/298)). * parameter `force` has now different meaning in `createLocalRepo()`. As suggested in ([#319](https://github.com/pbiecek/archivist/issues/319)) and ([#318](https://github.com/pbiecek/archivist/issues/318)) if forces to override existing backpack.db file. * Updated CITATION diff --git a/R/aread.R b/R/aread.R index b9502f4..c2aad34 100644 --- a/R/aread.R +++ b/R/aread.R @@ -74,3 +74,38 @@ aread <- function(md5hash){ } if (length(res) == 1) return(res[[1]]) else res } + +#' @title Read Artifacts Given as md5hashes from the Repository +#' +#' @description +#' \code{areadLocal} reads the artifact from the Local \link{Repository}. It's a wrapper around +#' \link{loadFromLocalRepo}. +#' +#' @details +#' Function \code{areadLocal} reads artifacts (by \code{md5hashes}) from Local Repository. +#' +#' @param md5hash A character vector which elements are consisting name of the repository and name of the artifact (MD5 hash) or it's abbreviation. +#' +#' @param repo A character with path to local repository. +#' +#' @author +#' Przemyslaw Biecek, \email{przemyslaw.biecek@@gmail.com} +#' +#' @template roxlate-references +#' @template roxlate-contact +#' +#' @family archivist +#' @rdname areadLocal +#' @export +areadLocal <- function(md5hash, repo){ + stopifnot( (is.character( repo ) & length( repo ) == 1) | is.null( repo ) ) + stopifnot( is.character( md5hash ) ) + + # work for vectors + res <- list() + for (md5h in md5hash) { + # at least 3 elements + res[[md5h]] <- loadFromLocalRepo(md5hash = md5h, value = TRUE, repoDir = repo) + } + if (length(res) == 1) return(res[[1]]) else res +} diff --git a/R/asearch.R b/R/asearch.R index be218d3..51048c3 100644 --- a/R/asearch.R +++ b/R/asearch.R @@ -149,3 +149,45 @@ asearch <- function( patterns, repo = NULL){ } res } + +#' @title Read Artifacts Given as a List of Tags +#' +#' @description +#' \code{asearchLocal} searches for artifacts that contain all specified \link{Tags} +#' and reads all of them from a local \link{Repository}. It's a wrapper around +#' \link{searchInLocalRepo} and \link{loadFromLocalRepo}. +#' +#' @details +#' Function \code{asearchLocal} reads all artifacts that contain given list of \code{Tags} +#' from the selected Local Repository. +#' +#' @param repo A character with path to local repository. +#' +#' @param patterns A character vector of \code{Tags}. Only artifacts that +#' contain all Tags are returned. +#' +#' @return This function returns a list of artifacts (by their values). +#' +#' @author +#' Przemyslaw Biecek, \email{przemyslaw.biecek@@gmail.com} +#' +#' @template roxlate-references +#' @template roxlate-contact +#' @family archivist +#' @rdname asearchLocal +#' @export +asearchLocal <- function( patterns, repo = NULL){ + stopifnot( (is.character( repo ) & length( repo ) == 1) | is.null( repo ) ) + stopifnot( is.character( patterns ) ) + + oblist <- multiSearchInLocalRepoInternal(patterns = patterns, + repoDir = repo, + intersect = TRUE) + if (length(oblist) > 0) { + res <- lapply(oblist, loadFromLocalRepo, value = TRUE) + names(res) <- oblist + } else { + res <- list() + } + res +} \ No newline at end of file diff --git a/man/areadLocal.Rd b/man/areadLocal.Rd new file mode 100644 index 0000000..bc6a7ba --- /dev/null +++ b/man/areadLocal.Rd @@ -0,0 +1,63 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/aread.R +\name{areadLocal} +\alias{areadLocal} +\title{Read Artifacts Given as md5hashes from the Repository} +\usage{ +areadLocal(md5hash, repo) +} +\arguments{ +\item{md5hash}{A character vector which elements are consisting name of the repository and name of the artifact (MD5 hash) or it's abbreviation.} + +\item{repo}{A character with path to local repository.} +} +\description{ +\code{areadLocal} reads the artifact from the Local \link{Repository}. It's a wrapper around +\link{loadFromLocalRepo}. +} +\details{ +Function \code{areadLocal} reads artifacts (by \code{md5hashes}) from Local Repository. +} +\section{Contact}{ + + +Bug reports and feature requests can be sent to +\href{https://github.com/pbiecek/archivist/issues}{https://github.com/pbiecek/archivist/issues} +} + +\references{ +Przemyslaw Biecek, Marcin Kosinski (2017). +archivist: An R Package for Managing, Recording and Restoring Data Analysis Results +Conditionally accepted for Journal of Statistical Software +URL https://github.com/pbiecek/archivist +} +\seealso{ +Other archivist: \code{\link{Repository}}, + \code{\link{Tags}}, \code{\link{\%a\%}}, + \code{\link{addHooksToPrint}}, \code{\link{addTagsRepo}}, + \code{\link{aformat}}, \code{\link{ahistory}}, + \code{\link{alink}}, \code{\link{aoptions}}, + \code{\link{archivist-package}}, \code{\link{aread}}, + \code{\link{asearchLocal}}, \code{\link{asearch}}, + \code{\link{asession}}, \code{\link{atrace}}, + \code{\link{cache}}, \code{\link{copyLocalRepo}}, + \code{\link{createLocalRepo}}, + \code{\link{createMDGallery}}, + \code{\link{deleteLocalRepo}}, + \code{\link{getRemoteHook}}, \code{\link{getTagsLocal}}, + \code{\link{loadFromLocalRepo}}, \code{\link{md5hash}}, + \code{\link{removeTagsRepo}}, \code{\link{restoreLibs}}, + \code{\link{rmFromLocalRepo}}, + \code{\link{saveToLocalRepo}}, + \code{\link{searchInLocalRepo}}, + \code{\link{setLocalRepo}}, + \code{\link{shinySearchInLocalRepo}}, + \code{\link{showLocalRepo}}, + \code{\link{splitTagsLocal}}, + \code{\link{summaryLocalRepo}}, + \code{\link{zipLocalRepo}} +} +\author{ +Przemyslaw Biecek, \email{przemyslaw.biecek@gmail.com} +} +\concept{archivist} diff --git a/man/asearchLocal.Rd b/man/asearchLocal.Rd new file mode 100644 index 0000000..af601b1 --- /dev/null +++ b/man/asearchLocal.Rd @@ -0,0 +1,70 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/asearch.R +\name{asearchLocal} +\alias{asearchLocal} +\title{Read Artifacts Given as a List of Tags} +\usage{ +asearchLocal(patterns, repo = NULL) +} +\arguments{ +\item{patterns}{A character vector of \code{Tags}. Only artifacts that +contain all Tags are returned.} + +\item{repo}{A character with path to local repository.} +} +\value{ +This function returns a list of artifacts (by their values). +} +\description{ +\code{asearchLocal} searches for artifacts that contain all specified \link{Tags} +and reads all of them from a local \link{Repository}. It's a wrapper around +\link{searchInLocalRepo} and \link{loadFromLocalRepo}. +} +\details{ +Function \code{asearchLocal} reads all artifacts that contain given list of \code{Tags} +from the selected Local Repository. +} +\section{Contact}{ + + +Bug reports and feature requests can be sent to +\href{https://github.com/pbiecek/archivist/issues}{https://github.com/pbiecek/archivist/issues} +} + +\references{ +Przemyslaw Biecek, Marcin Kosinski (2017). +archivist: An R Package for Managing, Recording and Restoring Data Analysis Results +Conditionally accepted for Journal of Statistical Software +URL https://github.com/pbiecek/archivist +} +\seealso{ +Other archivist: \code{\link{Repository}}, + \code{\link{Tags}}, \code{\link{\%a\%}}, + \code{\link{addHooksToPrint}}, \code{\link{addTagsRepo}}, + \code{\link{aformat}}, \code{\link{ahistory}}, + \code{\link{alink}}, \code{\link{aoptions}}, + \code{\link{archivist-package}}, + \code{\link{areadLocal}}, \code{\link{aread}}, + \code{\link{asearch}}, \code{\link{asession}}, + \code{\link{atrace}}, \code{\link{cache}}, + \code{\link{copyLocalRepo}}, + \code{\link{createLocalRepo}}, + \code{\link{createMDGallery}}, + \code{\link{deleteLocalRepo}}, + \code{\link{getRemoteHook}}, \code{\link{getTagsLocal}}, + \code{\link{loadFromLocalRepo}}, \code{\link{md5hash}}, + \code{\link{removeTagsRepo}}, \code{\link{restoreLibs}}, + \code{\link{rmFromLocalRepo}}, + \code{\link{saveToLocalRepo}}, + \code{\link{searchInLocalRepo}}, + \code{\link{setLocalRepo}}, + \code{\link{shinySearchInLocalRepo}}, + \code{\link{showLocalRepo}}, + \code{\link{splitTagsLocal}}, + \code{\link{summaryLocalRepo}}, + \code{\link{zipLocalRepo}} +} +\author{ +Przemyslaw Biecek, \email{przemyslaw.biecek@gmail.com} +} +\concept{archivist}