File tree Expand file tree Collapse file tree 3 files changed +39
-19
lines changed
Expand file tree Collapse file tree 3 files changed +39
-19
lines changed Original file line number Diff line number Diff line change 1- FROM clowder/pyclowder
1+ FROM clowder/pyclowder:latest
22
33ENV R_SCRIPT="" \
44 R_FUNCTION=""
55
6- RUN apt-get -q -q update \
7- && apt-get -y install --no-install-recommends r-base-core r-base-dev python-dev \
6+ RUN echo "deb http://cran.rstudio.com/bin/linux/ubuntu xenial/" > /etc/apt/sources.list.d/R.list \
7+ && apt-key adv --keyserver keyserver.ubuntu.com --recv E084DAB9 \
8+ && apt-get -q -q update \
9+ && apt-get -y install --no-install-recommends r-base-core r-base-dev \
810 && rm -rf /var/lib/apt/lists/* \
9- && pip install rpy2==2.8.6
10- RUN Rscript --vanilla -e "install.packages('jsonlite', repos='http://cran.rstudio.com/'); print(system.file(package = 'jsonlite')); q(status=as.integer(system.file(package = 'jsonlite') == ''))"
11+ && Rscript --vanilla -e "install.packages('jsonlite', repos='http://cran.rstudio.com/'); print(system.file(package = 'jsonlite')); q(status=as.integer(system.file(package = 'jsonlite') == ''))"
1112
12- COPY r_extractor.py /home/clowder/
13+ COPY r_extractor.py launcher.R /home/clowder/
1314
1415# install any packages
1516ONBUILD COPY packages.* Dockerfile /home/clowder/
Original file line number Diff line number Diff line change 1+ # !/usr/bin/env Rscript
2+
3+ # get environment variables
4+ r_script <- Sys.getenv(' R_SCRIPT' )
5+ r_function <- Sys.getenv(' R_FUNCTION' )
6+ if (r_function == ' ' ) {
7+ stop(" Need a function to call." )
8+ }
9+
10+ # command line arguments
11+ args <- commandArgs(trailingOnly = TRUE )
12+ if (length(args ) != 2 ) {
13+ stop(" Need 2 arguments (input_file, json_file)" )
14+ }
15+ input_file <- args [1 ]
16+ json_file <- args [2 ]
17+
18+ # source script file
19+ if (r_script != ' ' ) {
20+ source(r_script )
21+ }
22+
23+ # call function
24+ result <- do.call(r_function , list (input_file ))
25+
26+ # write result as json
27+ write(jsonlite :: toJSON(result , auto_unbox = TRUE ), json_file )
Original file line number Diff line number Diff line change 11#!/usr/bin/env python
22
33import json
4- import os
4+ import subprocess
5+ import tempfile
56
67from pyclowder .extractors import SimpleExtractor
7- import rpy2 .robjects as robjects
8-
9- r_script = os .getenv ("R_SCRIPT" )
10- r_function = os .getenv ("R_FUNCTION" )
118
129
1310class RExtractor (SimpleExtractor ):
1411 def process_file (self , input_file ):
15- r_result = robjects .r ('''
16- if ("%s" != "") {
17- source("%s")
18- }
19- result <- do.call("%s", list("%s"))
20- jsonlite::toJSON(result, auto_unbox=TRUE)
21- ''' % (r_script , r_script , r_function , input_file ))
22- return json .loads (str (r_result ))
12+ with tempfile .NamedTemporaryFile (suffix = ".json" ) as json_file :
13+ subprocess .check_call (['/home/clowder/launcher.R' , input_file , json_file .name ])
14+ return json .load (json_file .file )
2315
2416
2517RExtractor ().start ()
You can’t perform that action at this time.
0 commit comments