Skip to content

Commit

Permalink
Use Rscript for templated scripts (#12)
Browse files Browse the repository at this point in the history
* Use Rscript for templated scripts

* Cleanup

[ci skip]
  • Loading branch information
tersmitten authored Jun 16, 2016
1 parent 975f0df commit 2c35774
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 16 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ script:
# Test r installation
- >
echo 'print(gsub("I","O","PING"))'
| r
Rscript -e 'print(gsub("I","O","PING"))'
| grep -q 'PONG'
&& (echo 'Availability test: pass' && exit 0)
|| (echo 'Availability test: fail' && exit 1)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Set up the latest version of R in Ubuntu systems.
* `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`)
* `r_install`: [default: `['littler']`]: Additional (apt) packages to install (e.g. `r-recommended`)

* `r_packages_lib`: [default: `/usr/local/lib/R/site-library`]: The (default) library directory to install packages to
* `r_packages_repos`: [default: `"{{ r_cran_mirror }}"`]: The (default) URL to install packages from
Expand Down
3 changes: 2 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ r_cran_mirror: http://cran.rstudio.com/
r_bioclite_url: https://bioconductor.org/biocLite.R

r_install_dev: false
r_install: []
r_install:
- littler

r_packages_type: cran
r_packages_repos: "{{ r_cran_mirror }}"
Expand Down
2 changes: 1 addition & 1 deletion tasks/packages.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# tasks file for r
---
- name: packages | copy littler scripts
- name: packages | copy r scripts
template:
src: "usr/local/bin/{{ item.src }}"
dest: "/usr/local/bin/{{ item.dest }}"
Expand Down
15 changes: 8 additions & 7 deletions templates/usr/local/bin/R-install-package.j2
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
#!/usr/bin/env r
#!/usr/bin/env Rscript

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

package = argv[1]
package = argv[1];
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'])) {
if (type == "cran") {
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") {
} else if (type == 'bioconductor') {
withCallingHandlers({
source("{{ r_bioclite_url }}");
biocLite(package, lib=lib, suppressUpdates=TRUE, suppressAutoUpdate=TRUE, ask=FALSE);
}, warning = stop)
source('{{ r_bioclite_url }}')
biocLite(package, lib = lib, suppressUpdates = TRUE, suppressAutoUpdate = TRUE, ask = FALSE)
}, warning = stop);
} else {
cat("Unrecognised type\n");
q(status = 1);
Expand Down
7 changes: 4 additions & 3 deletions templates/usr/local/bin/R-remove-package.j2
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/usr/bin/env r
#!/usr/bin/env Rscript

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

package = argv[1]
package = argv[1];
lib = ifelse(is.na(argv[2]), '{{ r_packages_lib }}', argv[2]);

if (package %in% installed.packages(lib.loc = lib)[,'Package']) {
if (package %in% installed.packages(lib.loc = lib)[, 'Package']) {
withCallingHandlers(remove.packages(package, lib), warning = stop);
cat("changed\n");
} else {
Expand Down
1 change: 0 additions & 1 deletion vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ r_repository:

r_dependencies:
- r-base
- littler
- "{{ 'r-base-dev' if r_install_dev else '' }}"

0 comments on commit 2c35774

Please sign in to comment.