KWB-R / kwb.package

Install KWB Packages and Show Package Dependencies
https://kwb-r.github.io/kwb.package
MIT License
0 stars 0 forks source link

feat: cron job for ensuring KWB computers have access to "stable" KWB-R packages #6

Open mrustl opened 4 years ago

mrustl commented 4 years ago

Takeaways after discussing with @ItAtKwb for 2 hours what can be improved after the flusshygiene cron-job crash after updating KWB`s linux server to R 4.0.1 and realizing the messy R library installation workflow (2 cron job, one by @ItAtKwb and @wseis use different R libraries !!!) we ended up with some centralisation approach, which will not rule out all further issues but may be harmonize the "general" deployment at KWB of R packages.

The idea is that we provide an R script that can be used by @ItAtKwb to run a daily cron job on Linux/Windows servers so that:

always contain the latest version of R packages (always) on the "master" branch precompiled for both "linux" and "windows" and the latest KWB R release (currently: 4.01). For Windows @ItAtKwb proposed to adapt the .libPaths() variable .Renvironment file (could be "rolled" out by Marcus.

@hsonne what do you think????

Below a first incomplete and buggy first version how this could look like:

pkg_dependencies <- c("devtools", "remotes", "withr") 

install.packages(pkg_dependencies)

remotes::install_github("KWB-R/kwb.pkgstatus", upgrade = "always")

non_r_packages <- kwb.pkgstatus::get_non_r_packages()

gh_repos <- kwb.pkgstatus::get_github_repos()

gh_r_packages <- gh_repos[!gh_repos %in% non_r_packages]

install <- function(p) {
  remotes::install_github(p, upgrade = 'always', auth_token = devtools::github_pat(quiet = TRUE))
}

withr::with_libpaths("C:/Users/mrustl/Documents/testlib", install.packages(c("devtools", "remotes")))
withr::with_libpaths("C:/Users/mrustl/Documents/testlib", code = {
                     lapply(gh_r_packages$full_name[1:2], install)
                     })

For linux the known system dependencies for package installation are described here: https://github.com/KWB-R/pkgmeta/blob/master/.travis.yml#L9

mrustl commented 4 years ago

Didn`t remember but more or less solved in R package "pkgmeta": https://github.com/KWB-R/pkgmeta/blob/master/vignettes/analyse-rpackages.Rmd

(slightly modified)

remotes::install_github("kwb-r/pkgmeta") 

pkgs <- pkgmeta::get_github_packages()

session_metadata <- sessionInfo()
session_metadata

paths_list <- list(
  linux_lib_dir = "/usr/lib/R/site-library",
  win_lib_dir = "<root_dir>/kwbran/<r_version>",
  )
paths <- kwb.utils::resolve(paths_list, root_dir = "//servername", r_version = "4.0"))

## Install Packages

fs::dir_create(paths$win_dir, recursive = TRUE)
withr::with_libpaths(new = paths$win_lib_dir,  {
  install.packages("remotes", repos = "https://cran.rstudio.org")  }
)
for(pkg in pkgs$name) {
withr::with_libpaths(new = paths$pkglib, {
  code = remotes::install_github(repo = sprintf("kwb-r/%s", pkg),
  dependencies = TRUE,
  upgrade = "always",
  auth_token =  Sys.getenv("GITHUB_PAT"))})
}
mrustl commented 4 years ago

@ItAtKwb I now implemented a new function in kwb.package whith you could try out:

### install package dependencies
remotes::install_github("kwb-r/kwb.utils")
remotes::install_github("kwb-r/kwb.package@dev", 
dependencies = TRUE, 
upgrade = "always")

### define paths
paths_list <- list(
r_version = kwb.packages::get_r_version_majorminor(),
lib_linux = "/usr/lib/R/site-library",
lib_win = "<win_root_dir>/kwbran/<r_version>"
)

paths <- kwb.utils::resolve(paths_list,
win_root_dir = fs::path(tempdir()))

### get KWB-R package infos
pkgs <- pkgmeta::get_github_packages()

# install in windows lib
install_kwb_github_packages(lib = paths$lib_win, pkgs$full_name)

# install in linux lib
install_kwb_github_packages(lib = paths$lib_linux, pkgs$full_name)
mrustl commented 3 years ago

The solution for our public R packages may be our brand new CRAN like kwb-r universe repo: https://kwb-r.r-universe.dev

@ItAtKwb could you modify rstudio-prefs.json for all KWB computers by adding:

"secondary": "kwbr|https://kwb-r.r-universe.dev" to the cran_mirror settings as shown below?

grafik

Below location C:\Users\<user>\AppData\Roaming\RStudio\rstudio-prefs.json and structure of my config:

{
    "default_project_location": "~/RProjects",
    "windows_terminal_shell": "win-git-bash",
    "jobs_tab_visibility": "shown",
    "default_encoding": "UTF-8",
    "save_workspace": "never",
    "load_workspace": false,
    "document_author": "Michael Rustler",
    "initial_working_directory": "~",
    "cran_mirror": {
        "name": "Global (CDN)",
        "host": "RStudio",
        "url": "https://cran.rstudio.com/",
        "repos": "",
        "country": "us",
        "secondary": "kwbr|https://kwb-r.r-universe.dev"
    }
}
mrustl commented 3 years ago

After phone call with @ItAtKwb today morning we defined to modify Rprofile.site (because of problems to modify rstudio-prefs.json and because this solution is independent of Rstudio) on:

Content of Rprofile.site is set as follows:

## We set the cloud mirror, which is 'network-close' to everybody, as default
local({
  options(repos = c(kwbr = "https://kwb-r.r-universe.dev",  CRAN = "https://cloud.r-project.org"))
})

Afterwards we can simply install and update our public R packages (available on https://kwb-r.r-universe.dev):

Install

grafik

Update

grafik