From b840c4d2363af1a6b2db791119513e1cb5ac84cf Mon Sep 17 00:00:00 2001 From: edavidaja Date: Wed, 14 Jun 2023 21:29:12 -0400 Subject: [PATCH] reorganize installing packages --- _quarto.yml | 1 - install-single-package.qmd | 59 --------------------------------- installing-packages.qmd | 67 +++++++++++++++++++++++++++++++++++++- 3 files changed, 66 insertions(+), 61 deletions(-) delete mode 100644 install-single-package.qmd diff --git a/_quarto.yml b/_quarto.yml index 950823c..fc3e929 100644 --- a/_quarto.yml +++ b/_quarto.yml @@ -29,7 +29,6 @@ book: - reproducible-environments.qmd - installing-r.qmd - maintaining-r.qmd - - install-single-package.qmd - part: "All is Fail" chapters: - debugging-r.qmd diff --git a/install-single-package.qmd b/install-single-package.qmd deleted file mode 100644 index 7822a9a..0000000 --- a/install-single-package.qmd +++ /dev/null @@ -1,59 +0,0 @@ -# Install a source package - -The most common type of package you install is a **binary** package. Packages -released on CRAN are built as pre-compiled binaries. - -However often it is useful to install packages which do not have a pre-built -binary version available. This allows you to install development versions not -yet released on CRAN, as well as older versions of released packages. It also lets -you build your own packages locally. - -To install a source package you will need to [setup a development environment](#set-up-an-r-dev-environment). - -There are a few main functions used to install source packages. - -- `devtools::install_dev()` to install the latest development version of a CRAN package. ^[This will only work if the package includes a link to the development location in the package DESCRIPTION] -- `devtools::install_github()` to install a package directly from GitHub, even if it is not on CRAN. -- `devtools::install_version()` to install previously released CRAN versions of a package. - -For example `devtools::install_dev("dplyr")` will install the development -version of dplyr. `devtools::install_github("jimhester/lookup")` will install -Jim's lookup package (which is not on CRAN), and -`devtools::install_version("readr", "1.0.0")` will install readr 1.0.0. - -It is also possible to [fork, clone and work with a package -directly](https://happygitwithr.com/fork.html) then use `devtools::install()` -and `devtools::load_all()` to work with the package locally like you would with -a package you have created yourself. - -## Installation to a temporary library - -It is sometimes useful to install packages to a temporary library, so that they -don't affect your normal packages. This can be done by using the `lib` argument -to the devtools install functions, then using `lib.loc` in `library()` when you -load the package. - -```r -library(devtools) - -tmp_lib <- "~/tmp/tmp_library" -dir.create(tmp_lib) - -devtools::install_github("dill/beyonce", lib = tmp_lib) - -## restart R - -## explicitly load the affected packages from the temporary library -library(beyonce, lib.loc = tmp_lib) - -## your experimentation goes here - -## done? clean up! -unlink(tmp_lib, recursive = TRUE) -``` - -::: {.callout-note} -[Try the activity](https://raw.githubusercontent.com/jimhester/wtf-source-package/master/01_source-package_spartan.R): `usethis::use_course("rstd.io/wtf-source-package")` - -To practice installing various types of source packages. -::: diff --git a/installing-packages.qmd b/installing-packages.qmd index 8e38330..37778d8 100644 --- a/installing-packages.qmd +++ b/installing-packages.qmd @@ -27,4 +27,69 @@ Installed --"library()"--> Loaded end ``` -[R Packages](https://r-pkgs.org/Structure.html) covers these phases of the package lifecycle in much more detail. \ No newline at end of file +[R Packages](https://r-pkgs.org/Structure.html) covers these phases of the package lifecycle in much more detail. + +## Binary packages + +- where to get them +- how to know you got them + +## Source packages + +The most common type of package you install is a **binary** package. Packages +released on CRAN are built as pre-compiled binaries. + +However often it is useful to install packages which do not have a pre-built +binary version available. This allows you to install development versions not +yet released on CRAN, as well as older versions of released packages. It also lets +you build your own packages locally. + +To install a source package you will need to [setup a development environment](#set-up-an-r-dev-environment). + +There are a few main functions used to install source packages. + +- `devtools::install_dev()` to install the latest development version of a CRAN package. ^[This will only work if the package includes a link to the development location in the package DESCRIPTION] +- `devtools::install_github()` to install a package directly from GitHub, even if it is not on CRAN. +- `devtools::install_version()` to install previously released CRAN versions of a package. + +For example `devtools::install_dev("dplyr")` will install the development +version of dplyr. `devtools::install_github("jimhester/lookup")` will install +Jim's lookup package (which is not on CRAN), and +`devtools::install_version("readr", "1.0.0")` will install readr 1.0.0. + +It is also possible to [fork, clone and work with a package +directly](https://happygitwithr.com/fork.html) then use `devtools::install()` +and `devtools::load_all()` to work with the package locally like you would with +a package you have created yourself. + +## Installation to a temporary library + +It is sometimes useful to install packages to a temporary library, so that they +don't affect your normal packages. This can be done by using the `lib` argument +to the devtools install functions, then using `lib.loc` in `library()` when you +load the package. + +```r +library(devtools) + +tmp_lib <- "~/tmp/tmp_library" +dir.create(tmp_lib) + +devtools::install_github("dill/beyonce", lib = tmp_lib) + +## restart R + +## explicitly load the affected packages from the temporary library +library(beyonce, lib.loc = tmp_lib) + +## your experimentation goes here + +## done? clean up! +unlink(tmp_lib, recursive = TRUE) +``` + +::: {.callout-note} +[Try the activity](https://raw.githubusercontent.com/jimhester/wtf-source-package/master/01_source-package_spartan.R): `usethis::use_course("rstd.io/wtf-source-package")` + +To practice installing various types of source packages. +:::