Skip to content

Commit

Permalink
minor code formatting tweaks in intro vignette
Browse files Browse the repository at this point in the history
  • Loading branch information
achubaty committed Nov 17, 2017
1 parent 6bc9338 commit 4071d25
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions inst/doc/miniCRAN-introduction.rmd
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ Start by creating the dependency list:
library("miniCRAN")
# use Revolution Analytics CRAN mirror
revolution <- c(CRAN="http://cran.microsoft.com")
revolution <- c(CRAN = "http://cran.microsoft.com")
# Specify list of packages to download
pkgs <- c("foreach")
pkgList <- pkgDep(pkgs, repos=revolution, type="source", suggests = FALSE, availPkgs = cranJuly2014)
pkgList <- pkgDep(pkgs, repos = revolution, type = "source", suggests = FALSE, availPkgs = cranJuly2014)
pkgList
```

Expand All @@ -39,23 +39,23 @@ Next, create a repository with the function `makeRepo()`. In this example, get
dir.create(pth <- file.path(tempdir(), "miniCRAN"))
# Make repo for source and win.binary
makeRepo(pkgList, path=pth, repos=revolution, type=c("source", "win.binary"))
makeRepo(pkgList, path = pth, repos = revolution, type = c("source", "win.binary"))
```


Investigate the repository file structure:

```{r make-repo-3, eval=FALSE}
# List all files in miniCRAN
list.files(pth, recursive=TRUE, full.names=FALSE)
list.files(pth, recursive = TRUE, full.names = FALSE)
```


Use `pkgAvail` to list available packages in your repository:

```{r make-repo-4, eval=FALSE}
# Check for available packages
pkgAvail(repos=pth, type="win.binary")[, c(1:3, 5)]
pkgAvail(repos = pth, type = "win.binary")[, c(1:3, 5)]
```

# Install packages from your local repository
Expand All @@ -77,8 +77,8 @@ After creating a local miniCRAN repository, additional packages and their depend

```{r addto-repo-new-1, eval=FALSE}
# Add new packages (from CRAN) to the miniCRAN repo
addPackage("Matrix", path=pth, repos=revolution, type=c("source", "win.binary"))
pkgAvail(repos=pth, type="win.binary")[, c(1:3, 5)]
addPackage("Matrix", path = pth, repos = revolution, type = c("source", "win.binary"))
pkgAvail(repos = pth, type = "win.binary")[, c(1:3, 5)]
```

The value that is returned (invisibly) via `addPackage` is the number of packages written to the index file, *i.e.*, the total number of packages in the repo of that type.
Expand All @@ -91,12 +91,12 @@ To add a specific version of a package from CRAN (or another CRAN-like repositor

```{r addto-repo-old-1, eval=FALSE}
# create a data frame with the package and version info
oldVers <- data.frame(package=c("foreach", "codetools", "iterators"),
version=c("1.4.0", "0.2-7", "1.0.5"),
stringsAsFactors=FALSE)
oldVers <- data.frame(package = c("foreach", "codetools", "iterators"),
version = c("1.4.0", "0.2-7", "1.0.5"),
stringsAsFactors = FALSE)
# download old source package version and create repo index
addOldPackage(pkgList, path=pth, vers=oldVers$version, repos=revolution, type="source")
addOldPackage(pkgList, path = pth, vers = oldVers$version, repos = revolution, type = "source")
```

You will get a warning whenever there are multiple versions of a package saved in the repository. Currently, you need to manually remove duplicate versions before rebuilding the repository's package index.
Expand All @@ -105,8 +105,8 @@ Note: This last step is important, otherwise you may end up with a repo in an in

```{r addto-repo-old-2, eval=FALSE}
# List package versions in the miniCRAN repo (produces warning about duplicates)
pkgVersionsSrc <- checkVersions(pkgList, path=pth, type="source")
pkgVersionsBin <- checkVersions(pkgList, path=pth, type="win.binary")
pkgVersionsSrc <- checkVersions(pkgList, path = pth, type = "source")
pkgVersionsBin <- checkVersions(pkgList, path = pth, type = "win.binary")
# After inspecting package versions, remove old versions
basename(pkgVersionsSrc) # duplicate versions
Expand All @@ -115,14 +115,14 @@ basename(pkgVersionsBin)
file.remove(pkgVersionsSrc[c(2,4,6)])
# rebuild the package index after removing duplicate package versions
updateRepoIndex(pth, type=c("source", "win.binary"))
updateRepoIndex(pth, type = c("source", "win.binary"))
```

To see the updated list of packages available in the miniCRAN repo:

```{r addto-repo-old-3, eval=FALSE}
pkgAvail(pth, type="source")[, c(1:3, 5)] # contains the old versions
pkgAvail(pth, type="win.binary")[, c(1:3, 5)] # contains the current versions
pkgAvail(pth, type = "source")[, c(1:3, 5)] # contains the old versions
pkgAvail(pth, type = "win.binary")[, c(1:3, 5)] # contains the current versions
```


Expand All @@ -138,17 +138,17 @@ Checking for updated versions of the packages currently stored in the miniCRAN r

```{r update-repo-1, eval=FALSE}
# Check if updated packages are available
oldPackages(path=pth, repos=revolution, type="source")[, 1:3] # should need update
oldPackages(path=pth, repos=revolution, type="win.binary")[, 1:3] # should be current
oldPackages(path = pth, repos = revolution, type = "source")[, 1:3] # should need update
oldPackages(path = pth, repos = revolution, type = "win.binary")[, 1:3] # should be current
```


Update the versions of the packages currently stored in the miniCRAN repository. By default, a prompt is given to confirm the update for each package. This prompt can be suppressed using `ask=FALSE`, which will update all packages. Be careful using this option if you want to keep certain packages at an older version.

```{r update-repo-2, eval=FALSE}
# Update available packages
updatePackages(path=pth, repos=revolution, type="source", ask=FALSE) # should need update
updatePackages(path=pth, repos=revolution, type="win.binary", ask=FALSE) # should be current
updatePackages(path = pth, repos = revolution, type = "source", ask = FALSE) # should need update
updatePackages(path = pth, repos = revolution, type = "win.binary", ask = FALSE) # should be current
```


Expand Down

0 comments on commit 4071d25

Please sign in to comment.