Learn R Programming

miniCRAN (version 0.2.4)

checkVersions: Check for previous versions of packages in a miniCRAN repository.

Description

Checks for previous versions, and returns the file paths for packages with multiple versions. You can subsequently decide which version to keep.

Usage

checkVersions(pkgs = NULL, path = NULL, type = "source",
  Rversion = R.version)

Arguments

pkgs
Character vector of packages to be installed. If not provided, checks all files for multiple package versions.
path
The local path to the directory where the miniCRAN repo resides.
type
character, indicating the type of package to download and install. See install.packages.
Rversion
numeric version of the R system for which to fetch packages. See R_system_version.

Value

  • Returns invisibly the filepaths to packages with multiple versions for removal.

See Also

Other update repo functions: addOldPackage; addPackage; makeRepo, updateRepoIndex; oldPackages, updatePackages, updatePackages

Examples

Run this code
### `checkVersions` and `add.packages.miniCRAN` require an existing miniCRAN repo

# Specify list of packages to download
revolution <- c(CRAN="http://cran.revolutionanalytics.com")
pkgs <- c("foreach")

pdb <- cranJuly2014

pdb <- pkgAvail(repos=revolution, type="source")

pkgList <- pkgDep(pkgs, availPkgs=pdb, repos=revolution, type="source", suggests=FALSE)
pkgList

# Create temporary folder for miniCRAN
  dir.create(pth <- file.path(tempdir(), "miniCRAN"))

  # Make repo for source and win.binary
  makeRepo(pkgList, path=pth, repos=revolution, type="source")
  makeRepo(pkgList, path=pth, repos=revolution, type="win.binary")

  # Add other versions of a package (and assume these were added previously)
  oldVers <- data.frame(package=c("foreach", "codetools", "iterators"),
                        version=c("1.4.0", "0.2-7", "1.0.5"),
                        stringsAsFactors=FALSE)
  pkgs <- oldVers$package
  addOldPackage(pkgs, path=pth, vers=oldVers$version, repos=revolution, type="source")
  # NOTE: older binary versions would need to be build from source

  # List package versions in the miniCRAN repo (produces warning about duplicates)
  pkgVersionsSrc <- checkVersions(pkgs, path=pth, type="source")
  pkgVersionsBin <- checkVersions(pkgs, path=pth, type="win.binary")

  # After inspecting package versions, remove old versions
  basename(pkgVersionsSrc) # "foreach_1.4.0.tar.gz"  "foreach_1.4.2.tar.gz"
  basename(pkgVersionsBin) # "foreach_1.4.0.zip"     "foreach_1.4.2.zip"
  file.remove(c(pkgVersionsSrc[1], pkgVersionsBin[1]))

  # Rebuild package index after adding/removing files
  updateRepoIndex(pth, type=c("source", "win.binary"), Rversion=R.version)
  
  pkgAvail(pth, type="source")

  # Add new packages (from CRAN) to the miniCRAN repo
  addPackage("Matrix", path=pth, repos=revolution, type="source")
  addPackage("Matrix", path=pth, repos=revolution, type="win.binary")

  # Delete temporary folder
  unlink(pth, recursive=TRUE)

Run the code above in your browser using DataLab