6 Packages
When it comes to sharing your code with others, you may:
- Share an
.Rscript - Share an
.RDataimage - Build and share a package
- Packages we used already:
dplyr,tidyr,lubridate,foreign
A package bundles together code, data, documentation, and tests, and is easy to share with others. As of June 2019, there were over 14,000 packages available on the Comprehensive R Archive Network, or CRAN, the public clearing house for R packages. This huge variety of packages is one of the reasons that R is so successful: the chances are that someone has already solved a problem that you’re working on, and you can benefit from their work by downloading their package. - Chapter 1 Introduction, R Packages
SO: In R, what does “loaded via a namespace (and not attached)” mean?
- CRAN - R
- CPAN - Perl
- PyPI, Conda - Python
- npm - JavaScript
- As of Sep. 2021:
- there are over 18,000 packages indexed on MetaCRAN.
ggplot2is the most downloaded packagekniris the most depended upon package
- Many more packages are available on Github
Tidyverse is a collection of R packages
tibble, tidyverse’s data frameggplot2, graphicsdplyr, data manipulationtidyr, data tidying- …
- similar to
pandasfor Python
To see where your packages are saved on the computer:
.libPaths()To list all packages available on the computers:
lapply(.libPaths(), dir)With package
x:install.packages("x")to install from CRANlibrary("x")to use the packagepackage?xto get helppackage?graphicspackage?ggplot2
- Use cheat sheets
To create a package
?devtools::createA package has its own environment (see Fundamentals II)
ls("package:x")lists all objects in that package- e.g.
ls("package:graphics")