Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mrustl opened this issue Jun 17, 2020 · 4 comments
Assignees
Labels
enhancement New feature or request question Further information is requested

Comments

@mrustl
Copy link
Member

mrustl commented Jun 17, 2020

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:

  • Linux library: "/usr/lib/R/site-library"
  • KWB network drive (e.g.) : "//servername/kwbran/..." (preferably using "//servername" instead of "R:/")

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 mrustl added enhancement New feature or request question Further information is requested labels Jun 17, 2020
@mrustl mrustl pinned this issue Jun 17, 2020
@mrustl
Copy link
Member Author

mrustl commented Jun 17, 2020

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
Copy link
Member Author

mrustl commented Jun 18, 2020

@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
Copy link
Member Author

mrustl commented Jul 9, 2021

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
Copy link
Member Author

mrustl commented Jul 9, 2021

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:

  • rupelton: /opt/R/<r-version>/lib/R/etc/Rprofile.site (done by @ItAtKwb on 2021-07-09 11:45)
  • personal computers: C:/Program Files/R/<r-version>/etc/Rprofile.site (test case on @mrustl computer planned for 2021-07-12, if successful rollout via R 4.1.0 updates by @ItAtKwb)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants