Wednesday 19 July 2017

Reading Notes of R Packages

Cited from the Book "R Packages"

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Package Structure

devtools::install() is effectively a wrapper for R CMD INSTALL.

devtools::build() is a wrapper for R CMD build that turns source packages into bundles.

devtools::install_github() downloads a source package from GitHub, runs build() to make vignettes, and then uses R CMD INSTALL to do the install. 

devtools::install_url(), devtools::install_gitorious(), devtools::install_bitbucket() work similarly for packages found elsewhere on the internet.

You can prevent files in the package bundle from being included in the installed package using .Rinstignore.

devtools::load_all() and RStudio’s “Build and reload”, which allows you to skip install and load a source package directly into memory.

A library is simply a directory containing installed packages. You can have multiple libraries on your computer. In fact, almost every one has at least two: one for packages you’ve installed, and one for the packages that come with every R installation (like base, stats, etc). Normally, the directories with user-installed packages vary based on the version of R that you’re using. That’s why it seems like you lose all of your packages when you reinstall R — they’re still on your hard drive, but R can’t find them.

The main difference between library() and require() is what happens if a package isn’t found. While library()throws an error, require() prints a warning message and returns FALSE.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
R code

The first principle of using a package is that all R code goes in R/.



No comments:

Post a Comment