Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alterations in asearch and other functions due to #149 issue. #158

Merged
merged 3 commits into from
Dec 1, 2015
Merged
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
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export(searchInGithubRepo)
export(searchInLocalRepo)
export(setGithubRepo)
export(setLocalRepo)
export(setRepo)
export(shinySearchInLocalRepo)
export(showGithubRepo)
export(showLocalRepo)
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
archivist 1.9
----------------------------------------------------------------
* **New functions**:
1. Created wrappers around existing local and github functions: `multiSearchInRepo`, `setRepo`, `loadFromRepo`.
1. Created wrappers around existing local and github functions: `multiSearchInRepo` , `loadFromRepo`.
* **Bugs fixed**:
1. `asearch` function enables a user to read artifacts from default GitHub repository. In the previous version it was possible only in default local repository.
* **New features**:
Expand Down
4 changes: 2 additions & 2 deletions R/aread.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ aread <- function( md5hash){
stopifnot( length(elements) >= 3 | length(elements) == 1)
if (length(elements) == 1) {
# local directory
res[[md5h]] <- loadFromRepo(type = "local", md5hash = elements, value = TRUE)
res[[md5h]] <- loadFromRepo(md5hash = elements, value = TRUE)
} else {
# GitHub directory
res[[md5h]] <- loadFromRepo(type = "github", md5hash = elements[length(elements)],
res[[md5h]] <- loadFromRepo(md5hash = elements[length(elements)],
repo = elements[2],
repoDirGit = ifelse(length(elements) > 3, paste(elements[3:(length(elements)-1)], collapse="/"), FALSE),
user = elements[1], value = TRUE)
Expand Down
12 changes: 5 additions & 7 deletions R/asearch.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
#' exampleRepoDir <- tempfile()
#' createEmptyRepo(repoDir = exampleRepoDir)
#' ## setting default local repository
#' setRepo(type = "local", repoDir = exampleRepoDir)
#' setLocalRepo( repoDir = exampleRepoDir )
#'
#' saveToRepo(myplot123)
#' saveToRepo(iris)
Expand All @@ -79,7 +79,7 @@
#'
#' ### default GitHub version
#' ## Setting default github repository
#' setRepo(type = "github", user = "pbiecek", repo = "archivist")
#' setGithubRepo( user = "pbiecek", repo = "archivist")
#'
#' showGithubRepo(method = "tags")$tag
#' searchInGithubRepo(pattern = "class:lm")
Expand Down Expand Up @@ -113,22 +113,20 @@ asearch <- function( patterns, repo = NULL){
# use default repo
# oblist <- multiSearchInLocalRepo(patterns = patterns,
# intersect = TRUE)
oblist <- multiSearchInRepo(patterns = patterns,
type = aoptions("type"))
oblist <- multiSearchInRepo(patterns = patterns)
# if (length(oblist) > 0) {
# res <- lapply(oblist, aread)
# }
if (length(oblist) > 0) {
res <- lapply(oblist, loadFromRepo, type = aoptions("type"), value = TRUE)
res <- lapply(oblist, loadFromRepo, value = TRUE)
}
} else {
# at least 3 elements
# it's GitHub Repo
elements <- strsplit(repo, "/")[[1]]
stopifnot( length(elements) >= 2 )

oblist <- multiSearchInRepo(type = "github",
user = elements[1], repo=paste(elements[-1], collapse = "/"),
oblist <- multiSearchInRepo(user = elements[1], repo=paste(elements[-1], collapse = "/"),
patterns = patterns)
if (length(oblist)>0) {
res <- lapply(paste0(repo, "/", oblist), aread)
Expand Down
15 changes: 9 additions & 6 deletions R/loadFromRepo.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
#' If \code{repo} and \code{user} are set to \code{NULL} (as default) in Github mode then global parameters
#' set in \link{setGithubRepo} function are used.
#'
#' @param type A character denoting whether to use \code{local} or \code{github} version
#' while using \code{loadFromRepo} wrapper.
#'
#' @param repoDir A character denoting an existing directory from which an artifact will be loaded.
#' If it is set to \code{NULL} (by default), it will use the \code{repoDir} specified in \link{setLocalRepo}.
Expand Down Expand Up @@ -344,13 +342,18 @@ loadFromGithubRepo <- function( md5hash, repo = NULL, user = NULL, branch = "mas

#' @rdname loadFromRepo
#' @export
loadFromRepo <- function( type = aoptions("type"), md5hash, repoDir = NULL,
loadFromRepo <- function( md5hash, repoDir = NULL,
repo = NULL, user = NULL, branch = "master", repoDirGit = FALSE,
value = FALSE ){
stopifnot( is.character(type), length(type) == 1, type %in% c("local", "github") )
if ( type == "local" )

local <- (!is.null(aoptions("repoDir")) && is.null(repo)) || (!is.null(repoDir) && is.null(repo))
GitHub <- (is.null(repoDir) && !is.null(aoptions("repo"))) || (is.null(repoDir) && !is.null(repo))
if (local) {
loadFromLocalRepo( md5hash = md5hash, repoDir = repoDir, value = value )
else
} else if (GitHub) {
loadFromGithubRepo( md5hash = md5hash, repo = repo, user = user, branch = branch,
repoDirGit = repoDirGit, value = value )
} else {
stop("repo and repoDir parameters can not be used simultaneously.")
}
}
38 changes: 18 additions & 20 deletions R/searchInRepo.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
#' by the \link{saveToRepo} function. If the artifact
#' is not in the Repository then a logical value \code{FALSE} is returned.
#'
#' @param type A character denoting whether to use \code{local} or \code{github} version
#' while using \code{multiSearchInRepo} wrapper.
#'
#' @param pattern If \code{fixed = TRUE}: a character denoting a \code{Tag} which is to be searched for in the Repository.
#' It is also possible to specify \code{pattern} as a list of
Expand Down Expand Up @@ -272,24 +270,6 @@ multiSearchInLocalRepo <- function( patterns, repoDir = NULL, fixed = TRUE, inte
unique(unlist(md5hs))
}

#' @rdname searchInRepo
#' @export
multiSearchInRepo <- function( type = aoptions("type"),
patterns, fixed = TRUE, intersect = TRUE,
repoDir = NULL, realDBname = TRUE,
repo = NULL, user = NULL, branch = "master", repoDirGit = FALSE ){

stopifnot( is.character(type), length(type) == 1, type %in% c("local", "github") )

if ( type == "local" )
multiSearchInLocalRepo( patterns = patterns, repoDir = repoDir, fixed = fixed,
intersect = intersect, realDBname = realDBname )
else
multiSearchInGithubRepo( patterns = patterns, repo = repo, user = user, branch = branch,
repoDirGit = repoDirGit, fixed = fixed, intersect = intersect )
}


#' @rdname searchInRepo
#' @export
multiSearchInGithubRepo <- function( patterns, repo = NULL, user = NULL,
Expand All @@ -306,3 +286,21 @@ multiSearchInGithubRepo <- function( patterns, repo = NULL, user = NULL,
return( m )
}

#' @rdname searchInRepo
#' @export
multiSearchInRepo <- function(patterns, fixed = TRUE, intersect = TRUE,
repoDir = NULL, realDBname = TRUE,
repo = NULL, user = NULL, branch = "master", repoDirGit = FALSE ){

local <- (!is.null(aoptions("repoDir")) && is.null(repo)) || (!is.null(repoDir) && is.null(repo))
GitHub <- (is.null(repoDir) && !is.null(aoptions("repo"))) || (is.null(repoDir) && !is.null(repo))
if (local){
multiSearchInLocalRepo( patterns = patterns, repoDir = repoDir, fixed = fixed,
intersect = intersect, realDBname = realDBname )
} else if (GitHub) {
multiSearchInGithubRepo( patterns = patterns, repo = repo, user = user, branch = branch,
repoDirGit = repoDirGit, fixed = fixed, intersect = intersect )
} else {
stop("repo and repoDir parameters can not be used simultaneously.")
}
}
14 changes: 0 additions & 14 deletions R/setRepo.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
#'
#' \href{https://github.com/pbiecek/archivist/wiki}{https://github.com/pbiecek/archivist/wiki}
#'
#' @param type A character denoting whether to use \code{local} or \code{github} version
#' while using \code{setRepo} wrapper.
#'
#' @param repoDir A character denoting a directory of a Repository that we want to
#' make dafault. In this way, in the following function calls: \link{saveToRepo},
#' \link{loadFromLocalRepo},\link{searchInLocalRepo}, \link{rmFromRepo}, \link{zipLocalRepo},
Expand Down Expand Up @@ -157,17 +154,6 @@ setGithubRepo <- function( user, repo, branch = "master",
invisible(NULL)
}

#' @family archivist
#' @rdname setRepo
#' @export
setRepo <- function( type, repoDir, user, repo, branch = "master", repoDirGit = FALSE ){
stopifnot( is.character(type), length(type) == 1, type %in% c("local", "github") )
aoptions( "type", type )
if ( type == "local" )
setLocalRepo( repoDir = repoDir )
else
setGithubRepo( repo = repo, user = user, branch = branch, repoDirGit = repoDirGit )
}

useGithubSetupArguments <- function(){
# assign( "repo", get( ".repo", envir = .ArchivistEnv ), envir = parent.frame(2) )
Expand Down
8 changes: 2 additions & 6 deletions man/loadFromRepo.Rd

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

9 changes: 3 additions & 6 deletions man/searchInRepo.Rd

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

26 changes: 0 additions & 26 deletions man/setRepo.Rd

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