diff --git a/defaults/main.yml b/defaults/main.yml index 7e73c19..bff984f 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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 }}" diff --git a/tasks/packages.yml b/tasks/packages.yml index 3056ed0..599ad1c 100644 --- a/tasks/packages.yml +++ b/tasks/packages.yml @@ -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 @@ -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 diff --git a/templates/usr/local/bin/R-install-package.j2 b/templates/usr/local/bin/R-install-package.j2 index 4699564..71a915f 100644 --- a/templates/usr/local/bin/R-install-package.j2 +++ b/templates/usr/local/bin/R-install-package.j2 @@ -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') { diff --git a/templates/usr/local/bin/R-update-package.j2 b/templates/usr/local/bin/R-update-package.j2 index 8af0659..b50f8af 100644 --- a/templates/usr/local/bin/R-update-package.j2 +++ b/templates/usr/local/bin/R-update-package.j2 @@ -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); +} diff --git a/vars/main.yml b/vars/main.yml index 52db013..0de5ee8 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -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