Use and if Needed Install Packages from CRAN, BioConductor, CRAN Archive, and GitHub

This tries to attach a package if you have it; if not, it tries to install it from BioConductor or CRAN; if not available there, it tries to install it from the cran mirror on GitHub, which includes packages that have been removed from CRAN; if not available there, it looks for a matching other package on GitHub to install. Note this is sloppy practice and prone to all sorts of risks. However, there are use cases, such as quick scripting, or in a class where students already know best practices, where this can be useful. yearn was inspired by teaching in PhyloMeth, a course funded by an NSF CAREER award to the author (NSF DEB-1453424).

Sometimes you just yearn for a package you need to use. You feel guilty about this, but just want to load it with library() and have it just work -- and if you don't have the package installed already, simply have the script install it first without having to figure out if it's on CRAN, Bioconductor, or GitHub, etc. If you're in this sort of mood, you probably don't care about case: is it phangorn or Phangorn or phangoRn -- you might even be willing to tolerate a letter or two off (though not by default).

This is sloppy. You should know what packages you need, install them, consider keeping track of versions with packrat or similar. But for a quick and dirty analysis, or when facing a classroom of angry students who are trying to pull in packages for a class exercise, this can be handy ("Download these from CRAN; go to Bioconductor for this; then get this new package that's only on GitHub -- no, it's install_github() not install.github(), but, yeah, install.packages() -- wait, where are you going, class?"). So, to do this,


And then call a package you want with just


where pkgdown is just an example of a potential package (one used to create the yearn package webpage, in fact). Note that currently the package name should be a bare string, not in quotes. Another option, once yearn has been installed, is to use the :: syntax: yearn::yearn(pkgdown) without having to do the library call first.

The package goes through a standard procedure when you do this:

  1. It tries to load the package with require(). If it works, it's done.
  2. If not, it tries to find a matching package name (case insensitive) from CRAN and Bioconductor. If you pass a maxdist argument to yearn(), it will allow up to that many spelling mismatches. By default this is zero. If it finds a match, it installs it, then tries to load it.
  3. If this fails, it looks on GitHub. It first looks in the GitHub CRAN mirror -- this includes packages that used to be on CRAN. It installs it there if it finds it.
  4. Otherwise, it looks elsewhere on GitHub. If there's one R package that matches, it simply installs it. If there are several, it picks one based on whose repository it's in: an ROpenSci repo is probably more likely to have what you want than a random fork of it a student made for a class assignment. The list of github users that are my guesses can be seen in ?yearn. If you're using this to teach a class using your software, you might want to add your user name to the list.

This package uses some key functions from the githubinstall package on CRAN, written by Koji Makiyama, Atsushi Hayakawa, Shinya Uryu, Hiroaki Yutani, and Nagi Teramo. However, it also incorporates checking CRAN and Bioconductor first, and it does not offer the interactivity of the githubinstall package in cases of multiple matches (it also is pickier about spelling mismatches than githubinstall by default).

Again, use at your own risk. This package is chatty about potential problems and where it's downloading packages, but it could be that you're loading a package that has the same name of what you want but does something different, someone could have done something malicious with a package they put on GitHub, etc.

Work on this was partially funded by NSF CAREER award 1453424 to Brian O'Meara (the package is useful for the class I teach as part of that award).


yearn 0.1.3

  • Made default needing exact (other than case) match

yearn 0.1.2

  • Now pulls in bioconductor source so users can use the biocLite() function

yearn 0.1.1

  • Initial release
  • Core functionality of pulling from CRAN, bioconductor, cran github mirror, and github

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.1.3 by Brian O'Meara, a year ago

Browse source code at

Authors: Brian O'Meara [aut, cre]

Documentation:   PDF Manual  

GPL (>= 2) license

Imports githubinstall, devtools, BiocInstaller

Suggests testthat

See at CRAN