Skip to content

Instantly share code, notes, and snippets.

@andrewmoles2
Last active October 5, 2023 12:08
Show Gist options
  • Save andrewmoles2/18e1a636aeadc42f503212fde1ddc6ba to your computer and use it in GitHub Desktop.
Save andrewmoles2/18e1a636aeadc42f503212fde1ddc6ba to your computer and use it in GitHub Desktop.

Revisions

  1. andrewmoles2 revised this gist Jun 8, 2022. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion update.R
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,10 @@ my_pkg <- pak::pkg_list()
    # if loaded from finder
    saveRDS(object = my_pkg, file = "my_packages.rds")

    # upgrade R

    # --------------
    # now upgrade R - https://www.r-project.org/
    # --------------

    # after upgrade, bring back the rds file
    my_pkg <- readRDS("my_packages.rds")
  2. andrewmoles2 created this gist Jun 8, 2022.
    36 changes: 36 additions & 0 deletions update.R
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    # script to upgrade R and re-install all (or at least most) packages

    # Pre-upgrade: save your packages as an rds file
    my_pkg <- pak::pkg_list()

    # if loaded from RStudio
    #here::here("R", "update_packages", "my_packages.rds")
    # if loaded from finder
    saveRDS(object = my_pkg, file = "my_packages.rds")

    # upgrade R

    # after upgrade, bring back the rds file
    my_pkg <- readRDS("my_packages.rds")
    # first, install all the cran packages
    inst <- my_pkg$package[my_pkg$repository == "CRAN"]
    install.packages(inst, type = "binary", Ncpus = 6)

    # check what is installed
    now <- pak::pkg_list()

    # see what is missing
    missing <- my_pkg[!my_pkg$package %in% now$package, ]

    # if installed from github, make name vector
    add <- paste0(missing$remoteusername, "/", missing$remoterepo)
    add <- add[!add %in% "NA/NA"]

    # now install github
    pak::pak(add)

    # see if there is anything left
    final <- pak::pkg_list()
    final_missing <- my_pkg[!my_pkg$package %in% final$package, ]

    paste(final_missing$package)