Skip to content

Commit

Permalink
enable bioconductor-3.8 (#37)
Browse files Browse the repository at this point in the history
* enable bioconductor-3.8

* fix ansible-lint

* bioconductor refactoring

* bioconductor refactoring pass 2

* bioconductor - updated

* inverse task order - need to update a package before install an other one

* fix old.packages

* rename register

* Update R-update-package.j2

* re-order package install and update task

* remove retries from install and repository task

* re-order package install and remove task

Co-authored-by: Fanch <[email protected]>
  • Loading branch information
lecorguille and FanchTheSystem authored May 8, 2020
1 parent eb94a4c commit 40e9c2c
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 12 deletions.
2 changes: 0 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,3 @@ r_packages_repos: "{{ r_cran_mirror }}"
r_packages_lib: /usr/local/lib/R/site-library
r_packages: []
r_environment: {}

r_packages_from_github: "{{ r_packages | selectattr('type', 'defined') | selectattr('type', 'equalto', 'github') | map(attribute='name') | list | length > 0 }}"
18 changes: 15 additions & 3 deletions tasks/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@
environment: "{{ r_environment }}"
register: _r_install_package
changed_when: "_r_install_package.stdout_lines[-1] is defined and _r_install_package.stdout_lines[-1] == 'changed'"
with_items: "{{ r_packages_from_github | ternary(r_preset_package_remotes + r_packages, r_packages) }}"
with_items:
"{{
r_packages_from_github | ternary (r_preset_package_remotes, []) +
r_packages_from_bioconductor | ternary ((r_version_35 | ternary (r_preset_package_bioconductor, [])), []) +
r_packages
}}"
when: item.state is undefined or item.state == 'present'
tags:
- r-packages-install
Expand All @@ -53,11 +58,18 @@
command: >
R-update-package
{{ item.name }}
{% if item.lib is defined %}{{ item.lib }}{% endif %}
{{ item.type | default(r_packages_type) }}
{{ item.lib | default(r_packages_lib) }}
{% if item.repos is defined %}{{ item.repos }}{% endif %}
environment: "{{ r_environment }}"
register: _r_update_package
changed_when: "_r_update_package.stdout_lines[-1] is defined and _r_update_package.stdout_lines[-1] == 'changed'"
with_items: "{{ r_packages }}"
with_items:
"{{
r_packages_from_github | ternary (r_preset_package_remotes, []) +
r_packages_from_bioconductor | ternary ((r_version_35 | ternary (r_preset_package_bioconductor, [])), []) +
r_packages
}}"
when: item.state is defined and item.state == 'updated'
tags:
- r-packages-update
8 changes: 6 additions & 2 deletions templates/usr/local/bin/R-install-package.j2
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ if (!(package %in% installed.packages(lib.loc = lib)[, 'Package'])) {
}, warning = stop);
} else if (type == 'bioconductor') {
withCallingHandlers({
source('{{ r_bioclite_url }}')
biocLite(package, lib = lib, suppressUpdates = TRUE, suppressAutoUpdate = TRUE, ask = FALSE)
{% if r_version_35 %}
BiocManager::install(package, lib = lib, update = FALSE)
{% else %}
source('{{ r_bioclite_url }}')
biocLite(package, lib = lib, suppressUpdates = TRUE, suppressAutoUpdate = TRUE, ask = FALSE)
{% endif %}
cat("changed\n");
}, warning = stop);
} else if (type == 'github') {
Expand Down
37 changes: 32 additions & 5 deletions templates/usr/local/bin/R-update-package.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,44 @@

argv = commandArgs(trailingOnly = TRUE);
if (is.null(argv) | length(argv) < 1) {
cat("Usage: R-update-package package [lib] [repos]\n");
cat("Usage: R-update-package package [type] [lib] [repos]\n");
q(status = 1);
}

package = argv[1];
lib = ifelse(is.na(argv[2]), '{{ r_packages_lib }}', argv[2]);
repos = ifelse(is.na(argv[3]), '{{ r_packages_repos.rstrip('/') }}', argv[3]);
type = ifelse(is.na(argv[2]), '{{ r_packages_type }}', argv[2]);
lib = ifelse(is.na(argv[3]), '{{ r_packages_lib }}', argv[3]);
repos = ifelse(is.na(argv[4]), '{{ r_packages_repos.rstrip('/') }}', argv[4]);

if (package %in% old.packages(lib.loc = lib)[, 'Package']) {
if (type == 'github') {
repo = argv[1];
package = unlist(strsplit(repo, "/"))[2];
} else {
package = argv[1];
}

if (package %in% old.packages(lib.loc = lib, repos = repos)[, 'Package'] & type == 'cran') {
withCallingHandlers({
update.packages(package, lib, repos, ask = FALSE);
cat("changed\n");
}, warning = stop);
}

if (type == 'bioconductor') {
withCallingHandlers({
{% if r_version_35 %}
BiocManager::install(package, lib = lib, update = FALSE)
{% else %}
source('{{ r_bioclite_url }}')
biocLite(package, lib = lib, suppressUpdates = TRUE, suppressAutoUpdate = TRUE, ask = FALSE)
{% endif %}
cat("changed\n");
}, warning = stop);
}

if (type == 'github') {
withCallingHandlers({
library(remotes)
install_github(repo, lib = lib, force = TRUE)
cat("changed\n");
}, warning = stop);
}
7 changes: 7 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,12 @@ r_dependencies:
- r-base
- "{{ r_install_dev | ternary('r-base-dev', r_dependencies_dummy_package) }}"

r_packages_from_github: "{{ r_packages | selectattr('type', 'defined') | selectattr('type', 'equalto', 'github') | map(attribute='name') | list | length > 0 }}"

r_preset_package_remotes:
- name: remotes

r_packages_from_bioconductor: "{{ r_packages | selectattr('type', 'defined') | selectattr('type', 'equalto', 'bioconductor') | map(attribute='name') | list | length > 0 }}"

r_preset_package_bioconductor:
- name: BiocManager

0 comments on commit 40e9c2c

Please sign in to comment.