DesiQuintans / librarian

Install, Update, Load Packages from CRAN, Bioconductor, and GitHub in One Step.
GNU General Public License v3.0
54 stars 1 forks source link

unshelf() doesn't detach packages attached via meta-package #2

Closed RaoOfPhysics closed 6 years ago

RaoOfPhysics commented 6 years ago

Firstly, thanks for the nice package!

I wanted to ask if it's possible for unshelf() to catch all the packages attached via, say, tidyverse.

  1. Before using shelf():
> sessionInfo()

[…]

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] compiler_3.5.0
  1. After using shelf():
> librarian::shelf(tidyverse, here)
[…]
> sessionInfo()

[…]

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
 [1] here_0.1        tidyverse_1.2.1 forcats_0.3.0   stringr_1.3.1
 [5] dplyr_0.7.5     purrr_0.2.5     readr_1.1.1     tidyr_0.8.1
 [9] tibble_1.4.2    ggplot2_2.2.1

loaded via a namespace (and not attached):
 [1] tidyselect_0.2.4 reshape2_1.4.3   haven_1.1.1      lattice_0.20-35
 [5] colorspace_1.3-2 rlang_0.2.1      pillar_1.2.3     foreign_0.8-70
 [9] glue_1.2.0       withr_2.1.2      modelr_0.1.2     readxl_1.1.0
[13] bindrcpp_0.2.2   bindr_0.1.1      plyr_1.8.4       munsell_0.4.3
[17] gtable_0.2.0     cellranger_1.1.0 rvest_0.3.2      devtools_1.13.5
[21] psych_1.8.4      memoise_1.1.0    librarian_1.1.0  parallel_3.5.0
[25] broom_0.4.4      Rcpp_0.12.17     backports_1.1.2  scales_0.5.0
[29] jsonlite_1.5     mnormt_1.5-5     hms_0.4.2        digest_0.6.15
[33] stringi_1.2.2    rprojroot_1.3-2  grid_3.5.0       cli_1.0.0
[37] tools_3.5.0      magrittr_1.5     lazyeval_0.2.1   crayon_1.3.4
[41] pkgconfig_2.0.1  xml2_1.2.0       lubridate_1.7.4  assertthat_0.2.0
[45] httr_1.3.1       rstudioapi_0.7   R6_2.2.2         nlme_3.1-137
[49] compiler_3.5.0
  1. After using unshelf() -- here gets removed but the rest stay:
> librarian::unshelf(tidyverse, here)
[…]
> sessionInfo()

[…]

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] forcats_0.3.0 stringr_1.3.1 dplyr_0.7.5   purrr_0.2.5   readr_1.1.1
[6] tidyr_0.8.1   tibble_1.4.2  ggplot2_2.2.1

loaded via a namespace (and not attached):
 [1] tidyselect_0.2.4 reshape2_1.4.3   haven_1.1.1      lattice_0.20-35
 [5] colorspace_1.3-2 rlang_0.2.1      pillar_1.2.3     foreign_0.8-70
 [9] glue_1.2.0       withr_2.1.2      modelr_0.1.2     readxl_1.1.0
[13] bindrcpp_0.2.2   bindr_0.1.1      plyr_1.8.4       munsell_0.4.3
[17] gtable_0.2.0     cellranger_1.1.0 rvest_0.3.2      devtools_1.13.5
[21] psych_1.8.4      memoise_1.1.0    librarian_1.1.0  parallel_3.5.0
[25] broom_0.4.4      Rcpp_0.12.17     backports_1.1.2  scales_0.5.0
[29] jsonlite_1.5     mnormt_1.5-5     hms_0.4.2        digest_0.6.15
[33] stringi_1.2.2    rprojroot_1.3-2  grid_3.5.0       cli_1.0.0
[37] tools_3.5.0      magrittr_1.5     lazyeval_0.2.1   crayon_1.3.4
[41] pkgconfig_2.0.1  xml2_1.2.0       lubridate_1.7.4  assertthat_0.2.0
[45] httr_1.3.1       rstudioapi_0.7   R6_2.2.2         nlme_3.1-137
[49] compiler_3.5.0
DesiQuintans commented 6 years ago

Hi, sorry about the turn-around on this one. librarian 1.2.0 adds three new arguments to unshelf() to address this:

  1. also_depends, which detaches dependencies of packages named in ...
  2. safe, which does not detach packages if they are needed by other still-attached ones
  3. quiet, which suppresses a message created by safe stopping a detachment.
> shelf(tidyverse, janitor)  # Janitor needs dplyr and purrr
-- Attaching packages --------------------------------------- tidyverse 1.2.1 --
v ggplot2 2.2.1     v purrr   0.2.4
v tibble  1.4.2     v dplyr   0.7.5
v tidyr   0.8.1     v stringr 1.3.1
v readr   1.1.1     v forcats 0.3.0
-- Conflicts ------------------------------------------ tidyverse_conflicts() --
x dplyr::filter() masks stats::filter()
x dplyr::lag()    masks stats::lag()

> .Last.value
tidyverse   janitor 
TRUE      TRUE 

> librarian:::check_attached()
[1] "janitor"   "forcats"   "stringr"   "dplyr"     "purrr"     "readr"     "tidyr"     "tibble"   
[9] "ggplot2"   "tidyverse" "librarian" "stats"     "graphics"  "grDevices" "utils"     "datasets" 
[17] "methods"   "base"     

> unshelf(tidyverse, also_depends = TRUE, safe = TRUE, quiet = FALSE)
Some packages were not detached because other packages still need them:
    dplyr  purrr  tidyr
To force them to detach, use the 'safe = FALSE' argument.

> librarian:::check_attached()
[1] "janitor"   "dplyr"     "purrr"     "tidyr"     "librarian" "stats"     "graphics"  "grDevices"
[9] "utils"     "datasets"  "methods"   "base"     

> unshelf(tidyverse, also_depends = TRUE, safe = FALSE, quiet = FALSE)

> librarian:::check_attached()
[1] "janitor"   "librarian" "stats"     "graphics"  "grDevices" "utils"     "datasets"  "methods"  
[9] "base"