Skip to content

Commit

Permalink
fix(R microkernel): Set .libPaths and ensure requires() is truely…
Browse files Browse the repository at this point in the history
… quiet
  • Loading branch information
nokome committed Dec 8, 2021
1 parent 925d9ed commit 80c2281
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions rust/kernel-r/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ mod tests {

let (outputs, messages) = kernel.exec("a <- 1").await?;
assert!(messages.is_empty());
assert!(outputs.is_empty());
assert_json_eq!(outputs, json!([]));

let (outputs, messages) = kernel.exec("b = 2").await?;
assert!(messages.is_empty());
assert!(outputs.is_empty());
assert_json_eq!(outputs, json!([]));

let (outputs, messages) = kernel.exec("print(a)\nprint(b)\na_b <- a + b").await?;
assert!(messages.is_empty());
Expand Down
12 changes: 8 additions & 4 deletions rust/kernel-r/src/r-codec.r
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ requires <- function (pkgs) {
}
if (length(install) > 0) {
# Ensure that the user has a place that they can install packages
# The first of `.libPaths` is expected to be the user's own library
libs <- Sys.getenv("R_LIBS_USER", .libPaths()[1])
dir.create(libs, recursive = TRUE, showWarnings = FALSE)
# Note that `R_LIBS_USER` is set to a default value at R startup (if not already set)
lib <- Sys.getenv("R_LIBS_USER")
dir.create(lib, recursive = TRUE, showWarnings = FALSE)
# Add the lib to lib paths for any other installs in this session
.libPaths(lib)
for (pkg in install) {
install.packages(pkg, quiet = TRUE, repo = "https://cloud.r-project.org/")
require(pkg, character.only = TRUE, quietly = TRUE)
}
}
}
suppressMessages(requires(c("jsonlite", "base64enc")))
# Both capture.output and suppressMessages are require here to keep this
# truely quiet on all platforms
capture.output(suppressMessages(requires(c("jsonlite", "base64enc"))))

# Decode JSON to an R value
decode_value <- function(json) {
Expand Down

0 comments on commit 80c2281

Please sign in to comment.