install R for Stencila from R buildpack
MODIFY
repo2docker/buildpacks/base.py
repo2docker/buildpacks/base.py
@@ -301,7 +301,7 @@ class BuildPack:
for root, dirs, files in os.walk("."):
for filename in files:
- if filename.endswith(".test.jats.xml"):
+ if filename.endswith(".jats.xml"):
self.log.debug("Found a .jats.xml: %s", filename)
self._stencila_manifest_contexts = set()
@@ -558,22 +558,7 @@ class BaseImage(BuildPack):
pass
if self.stencila_manifest_contexts:
for context in self.stencila_manifest_contexts:
- if(context == 'r'):
-
- # TODO: can I trigger the RBuildPack from here?
-
- assemble_scripts.extend(
- [
- (
- "${NB_USER}",
- r"""
- R --quiet -e "library('devtools'); options(unzip = 'internal'); devtools::install_github('stencila/r', ref = 'f220361438432abca968d2e76a4efe7c5ddde7f1')" && \
- R --quiet -e "stencila::register()"
- """,
- )
- ]
- )
- elif(context == 'py' or context == 'pyjp'):
+ if(context == 'py' or context == 'pyjp'):
assemble_scripts.extend(
[
(
@@ -585,6 +570,8 @@ class BaseImage(BuildPack):
)
]
)
+ #elif(context == 'r'):
+ # handled in RBuildPack
if self.stencila_manifest_dir:
assemble_scripts.extend(
[

MODIFY
repo2docker/buildpacks/r.py
repo2docker/buildpacks/r.py
@@ -19,7 +19,14 @@ class RBuildPack(PythonBuildPack):
date snapshot of https://mran.microsoft.com/timemachine
from which libraries are to be installed.
- 2. An optional `install.R` file that will be executed at build time,
+ 2. A `DESCRIPTION` file signaling an R package, or
+ a Stencila document (*.jats.xml) with R code chunks (i.e. language="r")
+ is found:
+
+ MRAN snapshot is set to latest date that is guaranteed to exist
+ across timezones.
+
+ 3. (Optional) An `install.R` file that will be executed at build time,
and can be used for installing packages from both MRAN and GitHub.
The `r-base` package from Ubuntu apt repositories is used to install
@@ -64,15 +71,16 @@ class RBuildPack(PythonBuildPack):
unless a `requirements.txt` is present and we do not want to require the
presence of a `requirements.txt` to use R.
- Instead we just check if runtime.txt contains a string of the form
- `r-<YYYY>-<MM>-<DD>`
+ Instead we check the options described in the class comment above.
"""
# If no date is found, then self.checkpoint_date will be False
# Otherwise, it'll be a date object, which will evaluate to True
if self.checkpoint_date:
return True
+
description_R = 'DESCRIPTION'
- if not os.path.exists('binder') and os.path.exists(description_R):
+ if not os.path.exists('binder'):
+ if os.path.exists(description_R) or (self.stencila_manifest_contexts and "r" in self.stencila_manifest_contexts):
if not self.checkpoint_date:
# no R snapshot date set through runtime.txt
# set the R runtime to the latest date that is guaranteed to be on MRAN across timezones
@@ -133,6 +141,7 @@ class RBuildPack(PythonBuildPack):
- R's devtools package, at a particular frozen version (determined by MRAN)
- IRKernel
- nbrsessionproxy (to access RStudio via Jupyter Notebook)
+ - stencila R package (if Stencila document with R code chunks detected)
"""
rstudio_url = 'https://download2.rstudio.org/rstudio-server-1.1.419-amd64.deb'
# This is MD5, because that is what RStudio download page provides!
@@ -148,7 +157,7 @@ class RBuildPack(PythonBuildPack):
# IRKernel version - specified as a tag in the IRKernel repository
irkernel_version = '0.8.11'
- return super().get_build_scripts() + [
+ scripts = [
(
"root",
r"""
@@ -226,6 +235,21 @@ class RBuildPack(PythonBuildPack):
),
]
+ if self.stencila_manifest_contexts:
+ if "r" in self.stencila_manifest_contexts:
+ scripts += [
+ (
+ "${NB_USER}",
+ # Install and register stencila library
+ r"""
+ R --quiet -e "devtools::install_github('stencila/r', ref = 'f220361438432abca968d2e76a4efe7c5ddde7f1')" && \
+ R --quiet -e "stencila::register()"
+ """
+ ),
+ ]
+
+ return super().get_build_scripts() + scripts
+
def get_assemble_scripts(self):
"""
Return series of build-steps specific to this repository

install R for Stencila from R buildpack