Skip to content

Commit

Permalink
Add bioconductor install functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
tersmitten committed Apr 24, 2016
1 parent c26c79b commit 75f13e7
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 13 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Set up the latest version of R in Ubuntu systems.
#### Variables

* `r_cran mirror`: [default: `http://cran.rstudio.com/`]: Your favorite [CRAN mirror](http://cran.r-project.org/mirrors.html)
* `r_bioclite_url`: [default: `https://bioconductor.org/biocLite.R`]: The `biocLite.R` script URL for [Bioconductor](http://bioconductor.org/) installs

* `r_install_dev`: [default: `false`]: Whether or not install the `r-base-dev` package
* `r_install`: [default: `[]`]: Additional (apt) packages to install (e.g. `r-recommended`)

Expand All @@ -20,6 +22,7 @@ Set up the latest version of R in Ubuntu systems.
* `r_packages`: [default: `[]`]: (CRAN) Packages to install or remove
* `r_packages.{n}.name`: [required]: The name of the package
* `r_packages.{n}.state`: [optional, default: `present`]: The state of the package
* `r_packages.{n}.type`: [optional, default: `cran`]: The type of the package (e.g. `bioconductor`)
* `r_packages.{n}.lib`: [optional, default: `r_packages_lib`]: The library directory to install the package to
* `r_packages.{n}.repos`: [optional, default: `r_packages_repos`]: The URL to install the package from

Expand Down Expand Up @@ -50,9 +53,11 @@ None
# apt packages
r_install:
- r-recommended
# cran-r packages
# cran or bioconductor (R) packages
r_packages:
- name: dplyr
- name: Biobase
type: bioconductor
```
#### License
Expand Down
3 changes: 3 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# defaults file for r
---
r_cran_mirror: http://cran.rstudio.com/
r_bioclite_url: https://bioconductor.org/biocLite.R

r_install_dev: false
r_install: []

r_packages_type: cran
r_packages_repos: "{{ r_cran_mirror }}"
r_packages_lib: /usr/local/lib/R/site-library
r_packages: []
3 changes: 3 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ galaxy_info:
- trusty
galaxy_tags:
- system
- r
- cran-r
- statistics
dependencies: []
4 changes: 2 additions & 2 deletions tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
state: latest
update_cache: true
cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}"
with_items: r_dependencies
with_items: "{{ r_dependencies }}"
when: "item | trim != ''"
tags:
- r-install-dependencies
Expand All @@ -15,6 +15,6 @@
apt:
name: "{{ item }}"
state: latest
with_items: r_install
with_items: "{{ r_install }}"
tags:
- r-install-additional
16 changes: 12 additions & 4 deletions tasks/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,27 @@
dest: R-remove-package

- name: packages | install
command: "R-install-package {{ item.name }}{% if item.lib is defined %} {{ item.lib }}{% endif %}{% if item.repos is defined %} {{ item.repos }}{% endif %}"
command: >
R-install-package
{{ item.name }}
{{ item.type | default(r_packages_type) }}
{% if item.lib is defined %}{{ item.lib }}{% endif %}
{% if item.repos is defined %}{{ item.repos }}{% endif %}
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
with_items: "{{ r_packages }}"
when: item.state is undefined or item.state == 'present'
tags:
- r-packages-install

- name: packages | remove
command: "R-remove-package {{ item.name }}{% if item.lib is defined %} {{ item.lib }}{% endif %}"
command: >
R-remove-package
{{ item.name }}
{% if item.lib is defined %}{{ item.lib }}{% endif %}
register: r_remove_package
changed_when: "r_remove_package.stdout_lines[-1] is defined and r_remove_package.stdout_lines[-1] == 'changed'"
with_items: r_packages
with_items: "{{ r_packages }}"
when: item.state is defined and item.state == 'absent'
tags:
- r-packages-remove
2 changes: 1 addition & 1 deletion tasks/repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
repo: "{{ item.type }} {{ item.url }}"
state: present
update_cache: true
with_items: r_repository
with_items: "{{ r_repository }}"
tags:
- r-repository-add
21 changes: 16 additions & 5 deletions templates/usr/local/bin/R-install-package.j2
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
#!/usr/bin/env r

if (is.null(argv) | length(argv) < 1) {
cat("Usage: R-install-package package [lib] [repos]\n");
cat("Usage: R-install-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 }}', argv[3]);
type = ifelse(is.na(argv[2]), '{{ r_packages_type }}', argv[2]);
lib = ifelse(is.na(argv[3]), '{{ r_packages_lib }}', argv[3]);

if (!(package %in% installed.packages(lib.loc = lib)[,'Package'])) {
withCallingHandlers(install.packages(package, lib, repos), warning = stop);
if (!(package %in% installed.packages(lib.loc = lib)[, 'Package'])) {
if (type == "cran") {
repos = ifelse(is.na(argv[4]), '{{ r_packages_repos }}', argv[4]);
withCallingHandlers(install.packages(package, lib, repos), warning = stop);
} else if (type == "bioconductor") {
withCallingHandlers({
source("{{ r_bioclite_url }}");
biocLite(package, lib=lib, suppressUpdates=TRUE, suppressAutoUpdate=TRUE, ask=FALSE);
}, warning = stop)
} else {
cat("Unrecognised type\n");
q(status = 1);
}
cat("changed\n");
} else {
cat("unchanged\n");
Expand Down
1 change: 1 addition & 0 deletions tests/test.retry
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
localhost
3 changes: 3 additions & 0 deletions tests/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@

- name: foreign
state: absent

- name: Biobase
type: bioconductor
1 change: 1 addition & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
r_repository:
- type: deb
url: "{{ r_cran_mirror }}/bin/linux/ubuntu {{ ansible_distribution_release }}/"

r_dependencies:
- r-base
- littler
Expand Down

0 comments on commit 75f13e7

Please sign in to comment.