Skip to content

Commit a7b304e

Browse files
committed
[GR-2738] Provide convenient function install.fastr.packages to install rJava.
PullRequest: fastr/1806
2 parents 220fe62 + 7f2662a commit a7b304e

File tree

3 files changed

+73
-12
lines changed

3 files changed

+73
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
New features:
44

55
* interop and tooling: READ and WRITE of ActiveBinding may have side effects. This is communicated via `KEY_INFO` to the tools and other languages (e.g., a debugger may warn before evaluating an ActiveBinding)
6+
* the MRAN mirror used by FastR as default repo was moved to https://mran.microsoft.com/snapshot/2018-06-20
7+
* new function `install.fastr.packages` to install FastR rJava replacement and possibly other packages in the future
68

79
Added missing R builtins and C API
810

com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/utils/R/utils.R

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,53 @@
2020
# questions.
2121

2222
eval(expression({
23-
excludedPkgs <- c("rJava")
24-
excludedPkgsMsgs <- c(paste0(
25-
"CRAN rJava is not supported on FastR, but you can download and install rJava compatible replacement package ",
26-
"from https://github.com/oracle/fastr/master/com.oracle.truffle.r.pkgs/rJava.\n",
27-
" Install it using 'R --jvm CMD INSTALL {fastr}/com.oracle.truffle.r.pkgs/rJava' and make sure that 'which R' points to FastR. "))
23+
24+
.fastr.addHelpPath('/com/oracle/truffle/r/library/utils/Rd')
25+
26+
fastrRepoPath <- NULL
27+
28+
install.fastr.packages <- function(pkgs) {
29+
if (is.null(fastrRepoPath) || !file.exists(fastrRepoPath)) {
30+
workDir <- tempdir()
31+
download.file('https://api.github.com/repos/oracle/fastr/tarball/master', file.path(workDir, 'fastr-repo.tar.gz'))
32+
origFiles <- list.files(workDir)
33+
untar(file.path(workDir, 'fastr-repo.tar.gz'), exdir=workDir)
34+
repoName <- setdiff(list.files(workDir), origFiles)
35+
fastrRepoPath <<- file.path(workDir, repoName)
36+
}
37+
for (pkg in pkgs) {
38+
pkgPath <- file.path(fastrRepoPath, 'com.oracle.truffle.r.pkgs', pkg)
39+
if (file.exists(pkgPath)) {
40+
install.packages(pkgPath, repos=NULL)
41+
} else {
42+
stop(paste0("FastR doesn't provide patched version of package ", pkg, ". Use install.packages to install it."));
43+
}
44+
}
45+
invisible(NULL)
46+
}
47+
48+
pkgWarnings <- c(
49+
rJava = c(paste0(
50+
"CRAN rJava is not supported on FastR, but you can download and install rJava compatible replacement package ",
51+
"from https://github.com/oracle/fastr/master/com.oracle.truffle.r.pkgs/rJava.\n",
52+
"You can run function install.fastr.packages('rJava') to install it from GitHub.")),
53+
data.table = c(paste0(
54+
"CRAN data.table uses some C API that FastR cannot emulate, there is a patched version of data.table available ",
55+
"at https://github.com/oracle/fastr/master/com.oracle.truffle.r.pkgs/data.table.\n",
56+
"You can run function install.fastr.packages('data.table') to install it from GitHub.")),
57+
dplyr = c(paste0(
58+
"The current version of CRAN dplyr uses some C API that FastR cannot emulate.\n",
59+
"For the best results we recommend installing revision dbbb918771bb6f803f5f9a126a38b613f7af0211 from https://github.com/tidyverse/dplyr and its dependencies from CRAN.\n",
60+
"The installation of dplyr via `install.packages('dplyr')` already installed all the dependencies. If you wish so you can now override the problematic version of dplyr with:\n",
61+
"install.packages('https://api.github.com/repos/tidyverse/dplyr/tarball/dbbb918771bb6f803f5f9a126a38b613f7af0211', repos=NULL)"))
62+
)
63+
64+
excludedPkgs <- c('rJava', 'data.table')
2865

2966
fastRPkgFilter <- function (av) {
3067
# The following statement will assign the url of the FastR clone of rJava, when ready (possibly on GitHub).
68+
# Note: this will not work, the following code is creating the URL like so: {repo}/{pkgName}_{version}.
69+
# What we can do is to override certain URLs in the Download builtin
3170
#av["rJava","Repository"] <- "https://github.com/oracle/fastr/master/com.oracle.truffle.r.pkgs/rJava"
3271
found <- rownames(av) %in% excludedPkgs
3372
if (any(found)) {
@@ -39,15 +78,18 @@ eval(expression({
3978

4079
getDependencies.original <- getDependencies
4180
getDependencies <- function(pkgs, dependencies = NA, available = NULL, lib = .libPaths()[1L], binary = FALSE) {
42-
res <- getDependencies.original(pkgs, dependencies, available, lib, binary)
43-
44-
found <- excludedPkgs %in% pkgs
81+
res <- getDependencies.original(pkgs, dependencies, available, lib, binary)
82+
found <- names(pkgWarnings) %in% pkgs
4583
if (any(found)) {
46-
foundPkgMsgs <- excludedPkgsMsgs[which(found)]
47-
warning(paste(foundPkgMsgs, collapse="\n"), call. = FALSE)
84+
for (w in pkgWarnings[found]) {
85+
warning(w, call. = FALSE)
86+
}
4887
}
49-
5088
res
5189
}
5290

53-
}), asNamespace("utils"))
91+
}), asNamespace("utils"))
92+
93+
# export new public functions
94+
exports <- asNamespace("utils")[[".__NAMESPACE__."]][['exports']]
95+
assign('install.fastr.packages', 'install.fastr.packages', envir = exports)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
\name{install.fastr.packages}
2+
\alias{install.fastr.packages}
3+
\title{Installs FastR specific version of given packages from https://github.com/oracle/fastr/tree/master/com.oracle.truffle.r.pkgs}
4+
\usage{
5+
install.fastr.packages('rJava')
6+
}
7+
\arguments{
8+
\item{pkgs}{character vector of package names.}
9+
}
10+
\value{
11+
Invisible NULL.
12+
}
13+
\description{
14+
}
15+
\examples{
16+
install.fastr.packages('rJava')
17+
}

0 commit comments

Comments
 (0)