Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
andrie committed Jun 26, 2016
2 parents c12cae3 + cc7ff6e commit 6a9a3fc
Show file tree
Hide file tree
Showing 27 changed files with 397 additions and 264 deletions.
33 changes: 13 additions & 20 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
language: c
language: r
sudo: false
cache: packages

before_install:
- curl -OL http://raw.github.com/craigcitro/r-travis/master/scripts/travis-tool.sh
- chmod 755 ./travis-tool.sh
- ./travis-tool.sh bootstrap
repos:
CRAN: https://cloud.r-project.org

env: NOT_CRAN="true"

install:
- ./travis-tool.sh install_deps
- Rscript -e 'install.packages("igraph", repos=c(CRAN="http:/cran.revolutionanalytics.com"))'

script: ./travis-tool.sh run_tests

after_failure:
- ./travis-tool.sh dump_logs

notifications:
email:
on_success: change
on_failure: change

branches:
only:
- master
- release
- dev
- update-repo

notifications:
email:
on_success: change
on_failure: change



4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ Description: Makes it possible to create an internally consistent
subset. The user can then install packages from this repository directly,
rather than from CRAN. This is useful in production settings, e.g. server
behind a firewall, or remote locations with slow broadband access.
Version: 0.2.5
Version: 0.2.6
URL: https://github.com/RevolutionAnalytics/miniCRAN
BugReports: https://github.com/RevolutionAnalytics/miniCRAN/issues
Date: 2016-04-12
Date: 2016-06-26
Imports:
tools,
XML,
Expand Down
11 changes: 11 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
miniCRAN v0.2-6 (Release date: 2016-06-26)
==============

* allow using `makeRepo()` to create a miniCRAN repo from an existing local miniCRAN, i.e. the repos contains file:/// prefix. This enables a use case in the AzureML package. (#76)
* easily manage packages for all three Operating Systems (#24)
* fix inconsistent use of Rversion in `addPackage()` (#42)


miniCRAN v0.2-5 (Release date: 2016-04-12)
==============

* plot.pkgDepGraph() now displays legend only for edges that are actually in graph
* make consistent use of Rversion argument (#42)


miniCRAN v0.2-4 (Release date: 2016-03-27)
==============

* Changed copyright to Microsoft


miniCRAN v0.2-2 (Release date: 2015-03-25)
==============

Expand Down
2 changes: 1 addition & 1 deletion R/MRAN.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MRAN <- function(snapshot){
url <- "http://mran.microsoft.com"
url <- "https://mran.microsoft.com"
if(missing("snapshot") || is.null(snapshot)){
url
} else {
Expand Down
55 changes: 29 additions & 26 deletions R/addPackages.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#'
#' @param type character, indicating the type of package to download and install. See \code{\link{install.packages}}.
#'
#' @param Rversion numeric version of the R system for which to fetch packages. See \code{\link{R_system_version}}.
#' @param Rversion Version of R. Can be specified as a character string with the two digit R version, e.g. "3.1". Defaults to \code{\link{R.version}}
#'
#' @return Returns invisibly the filepaths to packages with multiple versions for removal.
#'
Expand Down Expand Up @@ -46,11 +46,11 @@ checkVersions <- function(pkgs=NULL, path=NULL, type="source",
#' @inheritParams makeRepo
#' @inheritParams pkgDep
#'
#' @param Rversion numeric version of the R system for which to fetch packages. See \code{\link{R_system_version}}.
#' @param Rversion Version of R. Can be specified as a character string with the two digit R version, e.g. "3.1". Defaults to \code{\link{R.version}}
#'
#' @param deps logical indicating whether the package dependencies should be added (default \code{TRUE}).
#'
#' @return Installs the packages, rebuilds the package index, and invisibly returns the number of packages writen to the index files.
#' @return Installs the packages, rebuilds the package index, and invisibly returns the number of packages written to the index files.
#'
#' @importFrom tools write_PACKAGES
#' @export
Expand All @@ -62,27 +62,32 @@ addPackage <- function(pkgs=NULL, path=NULL, repos=getOption("repos"),
type="source", Rversion=R.version,
writePACKAGES=TRUE, deps=TRUE, quiet=FALSE) {
if (is.null(path) || is.null(pkgs)) stop("path and pkgs must both be specified.")
prev <- checkVersions(pkgs=pkgs, path=path, type=type, Rversion=Rversion)
prev.df <- getPkgVersFromFile(prev)

if (deps) pkgs <- pkgDep(pkgs, repos=repos, type=type)
lapply(type, function(t) {
prev <- checkVersions(pkgs=pkgs, path=path, type=t, Rversion=Rversion)
prev.df <- getPkgVersFromFile(prev)

makeRepo(pkgs=pkgs, path=path, repos=repos, type=type, Rversion=Rversion,
download=TRUE, writePACKAGES=FALSE, quiet=quiet)
if (deps) pkgs <- pkgDep(pkgs, repos = repos, type = t, Rversion = Rversion)

if (length(prev)) {
curr <- suppressWarnings(
checkVersions(pkgs=pkgs, path=path, type=type, Rversion=Rversion)
)
curr.df <- getPkgVersFromFile(curr)
makeRepo(pkgs = pkgs, path = path, repos = repos, type = t, Rversion = Rversion,
download = TRUE, writePACKAGES = FALSE, quiet = quiet)

dupes <- with(curr.df, package[duplicated(package)])
if (length(dupes)) {
old <- lapply(dupes, function(x) { grep(paste0("^", x), basename(prev)) } )
file.remove(prev[unlist(old)])
if (length(prev)) {
curr <- suppressWarnings(
checkVersions(pkgs=pkgs, path=path, type=t, Rversion=Rversion)
)
curr.df <- getPkgVersFromFile(curr)

dupes <- with(curr.df, package[duplicated(package)])
if (length(dupes)) {
old <- lapply(dupes, function(x) { grep(paste0("^", x), basename(prev)) } )
file.remove(prev[unlist(old)])
}
}
}
if (writePACKAGES) invisible(updateRepoIndex(path=path, type=type, Rversion=Rversion))
})

n <- if (writePACKAGES) updateRepoIndex(path=path, type=type, Rversion=Rversion)
return(invisible(n))
}


Expand All @@ -99,7 +104,7 @@ addPackage <- function(pkgs=NULL, path=NULL, repos=getOption("repos"),
#'
#' @param vers The package version to install.
#'
#' @return Installs the packages, rebuilds the package index, and invisibly returns the number of packages writen to the index files.
#' @return Adds the packages, rebuilds the package index, and invisibly returns the number of packages written to the index files.
#'
#' @note Dependencies for old package versions cannot be determined automatically and must be specified by the user in \code{pkgs} and \code{vers}. Thus, \code{deps=FALSE} is the default for this function.
#'
Expand All @@ -119,8 +124,8 @@ addOldPackage <- function(pkgs=NULL, path=NULL, vers=NULL,
if (type!="source") stop("Older binary versions are not normally available on CRAN. ",
"You must build the binary versions from source.")
if(deps) {
message("Unable to automatically determine dependency version information.")
message("Use pkgs and vers to identify which dependecies and their versions to download.")
message("Unable to automatically determine dependency version information.\n",
"Use pkgs and vers to identify which dependecies and their versions to download.")
}
vers <- as.character(vers)
oldPkgs <- file.path(repos, repoPrefix(type, R.version), "Archive",
Expand All @@ -129,10 +134,8 @@ addOldPackage <- function(pkgs=NULL, path=NULL, vers=NULL,
pkgPath <- repoBinPath(path=path, type=type, Rversion=Rversion)
if(!file.exists(pkgPath)) dir.create(pkgPath, recursive=TRUE)
sapply(oldPkgs, function(x) {
result <- download.file(x, destfile=file.path(pkgPath, basename(x)),
method="auto",
mode="wb",
quiet=quiet)
result <- utils::download.file(x, destfile=file.path(pkgPath, basename(x)),
method="auto", mode="wb", quiet=quiet)
if(result!=0) warning("error downloading file ", x)
})
if (writePACKAGES) invisible(updateRepoIndex(path=path, type=type, Rversion))
Expand Down
2 changes: 1 addition & 1 deletion R/helpers.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Get the path to the repo directory containing the package files.
#'
#' @param Rversion numeric version of the R system for which to fetch packages. See \code{\link{R_system_version}}.
#' @param Rversion Version of R. Can be specified as a character string with the two digit R version, e.g. "3.1". Defaults to \code{\link{R.version}}
#'
#' @param type character, indicating the type of package to download and install. See \code{\link{install.packages}}.
#'
Expand Down
76 changes: 50 additions & 26 deletions R/makeRepo.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,42 +36,64 @@
#' @note Internally makes use of \code{\link[utils]{download.packages}} and \code{\link{write_PACKAGES}}
#'
#' @inheritParams pkgDep
#'
#'
#' @param pkgs Character vector of packages to download
#'
#'
#' @param path Destination download path. This path is the root folder of your new repository.
#'
#'
#' @param Rversion List with two named elements: `major` and `minor`. If not supplied, defaults to system version of R, using \code{\link{R.version}}. Only used if \code{type} is not "source"
#'
#'
#' @param download If TRUE downloads packages.
#'
#'
#' @param quiet If TRUE, suppress status messages (if any), and the progress bar during download.
#'
#'
#' @param writePACKAGES If TRUE, calls \code{\link{write_PACKAGES}} to update the repository PACKAGES file.
#'
#' @export
#' @family update repo functions
#'
#'
#' @example /inst/examples/example_makeRepo.R
makeRepo <- function(pkgs, path, repos=getOption("repos"), type="source",
Rversion=R.version, download=TRUE, writePACKAGES=TRUE, quiet=FALSE) {
if(!file.exists(path)) stop("Download path does not exist")
pkgPath <- repoBinPath(path=path, type=type, Rversion=Rversion)
if(!file.exists(pkgPath)) {
result <- dir.create(pkgPath, recursive=TRUE, showWarnings = FALSE)
if(result) {
if(!quiet) message("Created new folder: ", pkgPath)
} else {
stop("Unable to create repo path: ", pkgPath)

downloaded <- lapply(type, function(type) {
pkgPath <- repoBinPath(path=path, type=type, Rversion=Rversion)
if(!file.exists(pkgPath)) {
result <- dir.create(pkgPath, recursive=TRUE, showWarnings = FALSE)
if(result) {
if(!quiet) message("Created new folder: ", pkgPath)
} else {
stop("Unable to create repo path: ", pkgPath)
}
}

pdb <- pkgAvail(repos = repos, type=type, Rversion = Rversion)

if(download) {
utils::download.packages(pkgs, destdir=pkgPath, available=pdb, repos=repos,
contriburl = contribUrl(repos, type, Rversion),
type=type, quiet=quiet)
}
})

if(download){

downloaded <- downloaded[[1]][, 2]

fromLocalRepos <- grepl("^file://", repos)
if(fromLocalRepos){
# need to copy files to correct folder
repoPath <- gsub("^file:///", "", repos)
repoPath <- normalizePath(repoPath, winslash = "/")
newPath <- gsub(repoPath, normalizePath(path, winslash = "/"), downloaded)
file.copy(downloaded, newPath)
downloaded <- newPath
}
}

pdb <- pkgAvail(repos = repos, type=type, Rversion = Rversion)

if(download) utils::download.packages(pkgs, destdir=pkgPath, available=pdb, repos=repos,
contriburl = contribUrl(repos, type, Rversion),
type=type, quiet=quiet)
if(writePACKAGES) updateRepoIndex(path=path, type=type, Rversion=Rversion)
if(download) downloaded else character(0)
}


Expand All @@ -80,11 +102,13 @@ makeRepo <- function(pkgs, path, repos=getOption("repos"), type="source",
#' @rdname makeRepo
#' @export
updateRepoIndex <- function(path, type="source", Rversion=R.version) {
lapply(type, function(type){
n <- lapply(type, function(type){
pkgPath <- repoBinPath(path=path, type=type, Rversion=Rversion)
if(grepl("mac.binary", type)) type <- "mac.binary"
tools::write_PACKAGES(dir=pkgPath, type=type)
})
names(n) <- type
return(n)
}


Expand All @@ -97,11 +121,11 @@ updateRepoIndex <- function(path, type="source", Rversion=R.version) {
makeLibrary <- function(pkgs, path, type="source"){
.Deprecated("makeRepo")
NULL
# if(!file.exists(path)) stop("Download path does not exist")
# wd <- getwd()
# on.exit(setwd(wd))
# setwd(normalizePath(path))
# message(getwd())
# download.packages(pkgs, destdir=path, type=type)
# if(!file.exists(path)) stop("Download path does not exist")
# wd <- getwd()
# on.exit(setwd(wd))
# setwd(normalizePath(path))
# message(getwd())
# download.packages(pkgs, destdir=path, type=type)
}

23 changes: 18 additions & 5 deletions R/testthat_helpers.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
# helper functions for testing

# Returns TRUE if a URL can be accessed
is.online <- function(url = MRAN()){
z <- tryCatch(suppressWarnings(readLines(url, n = 10, warn = FALSE)),
error = function(e)e
)
if(inherits(z, "error")) return(FALSE)
is.online <- function(url = MRAN(), tryHttp = TRUE){
readFromUrl <- function(url){
z <- tryCatch(suppressWarnings(readLines(url, n = 1, warn = FALSE)),
error = function(e)e
)
!inherits(z, "error")
}

if(!readFromUrl(url)){
if(grepl("^https://", url) && tryHttp){
url <- sub("^https://", "http://", url) # for older versions of R
if(!readFromUrl(url))
return(FALSE)
} else {
return(FALSE)
}
}

TRUE
}

Expand Down
Loading

0 comments on commit 6a9a3fc

Please sign in to comment.