Skip to content

Commit

Permalink
fixes for #298
Browse files Browse the repository at this point in the history
  • Loading branch information
pbiecek committed Nov 24, 2017
1 parent 429e7b9 commit aa49767
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
35 changes: 35 additions & 0 deletions R/aread.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
42 changes: 42 additions & 0 deletions R/asearch.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
63 changes: 63 additions & 0 deletions man/areadLocal.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions man/asearchLocal.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit aa49767

Please sign in to comment.