[pull] master from opencpu:master by pull[bot] · Pull Request #14 · httpsgithu/opencpu · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
50 changes: 50 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
pull_request:

name: R-CMD-check.yaml

permissions: read-all

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: macos-13, r: 'release'}
- {os: macos-14, r: 'release'}
- {os: windows-latest, r: '4.1'}
- {os: windows-latest, r: '4.2'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.*
!/.gitignore
!/.Rbuildignore
!/.travis.yml
Expand Down
16 changes: 0 additions & 16 deletions .travis.yml

This file was deleted.

18 changes: 10 additions & 8 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Package: opencpu
Title: Producing and Reproducing Results
Version: 2.2.8
Authors@R: person("Jeroen", "Ooms", role = c("aut", "cre"), email = "jeroen@berkeley.edu",
Version: 2.2.15
Authors@R: person("Jeroen", "Ooms", role = c("aut", "cre"), email = "jeroenooms@gmail.com",
comment = c(ORCID = "0000-0002-4035-0289"))
License: Apache License 2.0
Encoding: UTF-8
URL: https://www.opencpu.org (website)
https://github.com/opencpu/opencpu (devel)
URL: https://www.opencpu.org
https://opencpu.r-universe.dev/opencpu
BugReports: https://github.com/opencpu/opencpu/issues
Depends:
R (>= 3.0.0)
Expand All @@ -20,6 +20,9 @@ Imports:
webutils (>= 0.6),
curl (>= 4.0),
rappdirs,
rlang,
vctrs,
methods,
zip,
mime,
protolite,
Expand All @@ -30,17 +33,16 @@ Suggests:
unix (>= 1.5.3),
haven,
pander,
R.rsp,
svglite
SystemRequirements: pandoc, apparmor (optional)
VignetteBuilder: knitr, R.rsp
Description: A system for embedded scientific computing and reproducible research with R.
Description: A system for embedded scientific computing and reproducible research with R
as described in <doi:10.48550/arXiv.1406.4806>.
The OpenCPU server exposes a simple but powerful HTTP api for RPC and data interchange
with R. This provides a reliable and scalable foundation for statistical services or
building R web applications. The OpenCPU server runs either as a single-user development
server within the interactive R session, or as a multi-user Linux stack based on Apache2.
The entire system is fully open source and permissively licensed. The OpenCPU website
has detailed documentation and example apps.
LazyData: yes
RoxygenNote: 7.1.1
RoxygenNote: 7.3.2.9000
Roxygen: list(markdown = TRUE)
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

S3method(print,opencpu_info)
export(available_apps)
export(install_apps)
export(installed_apps)
Expand Down
15 changes: 15 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
2.2.13
- Fix 'anchored' man links for CRAN
- Raise default memory limit on cloud server to 1e10 for V8

2.2.11
- Errors raised by R now by default include a backtrace if available. You can
opt-out by setting 'error.backtrace' to false in your user.conf.
- Fix error.showcall to actually show/hide the call from errors.

2.2.10
- Fix getRversion type for CRAN

2.2.9
- Use packageStartupMessage() for loading messages

2.2.8
- Fixes for R-4.2 changes in R_LIBS_SITE and R_LIBS_USER
- Default platform is now Ubuntu-22.04 with R-4.2
Expand Down
2 changes: 1 addition & 1 deletion R/config.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ config <- local({
confpaths <- character()

load <- function(filepath){
message("Loading config from ", filepath)
packageStartupMessage("Loading config from ", filepath)
confpaths <<- c(confpaths, filepath)
newconf <- as.list(fromJSON(filepath));
for(i in seq_along(newconf)){
Expand Down
44 changes: 43 additions & 1 deletion R/evaluate.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ evaluate_input <- function(input, args = NULL, storeval = FALSE) {

#setup handler
error_object <- NULL
cur_env <- rlang::current_env()
myhandler <- evaluate::new_output_handler(value = function(myval, visible = TRUE){
if(isTRUE(storeval) && is.null(error_object)){
assign(".val", myval, sessionenv);
Expand All @@ -12,11 +13,14 @@ evaluate_input <- function(input, args = NULL, storeval = FALSE) {
cat("List of length ", length(myval), "\n")
cat(paste("[", names(myval), "]", sep="", collapse="\n"))
} else {
getFromNamespace("render", "evaluate")(myval)
evaluate_render(myval)
}
}
invisible()
}, error = function(e){
if (isTRUE(config("error.backtrace"))) {
e$trace <- rlang::trace_back(top=cur_env)
}
error_object <<- e
})

Expand All @@ -37,10 +41,48 @@ evaluate_input <- function(input, args = NULL, storeval = FALSE) {
}
res <- evaluate::evaluate(input = input, envir = sessionenv, stop_on_error = 1, output_handler = myhandler)


if(length(error_object) && length(error_object$call) && isTRUE(config("error.backtrace"))){
error_object <- clean_trace(error_object)
}

# return both
list (
res = res,
sessionenv = sessionenv,
error = error_object
)
}

clean_trace <- function(err){
if (!is.null(err$trace)) {
tr <- err$trace
n <- nrow(tr)

isErrorHandler <- vapply(tr$call,
function(x) identical(x[[1]], quote(.handleSimpleError)), logical(1))
errorHandlerIndex <- min(c(length(isErrorHandler)+1, which(isErrorHandler)))

isOverheadCall <- tr$namespace[seq_len(errorHandlerIndex - 1)] %in% c("evaluate", "opencpu") # only check before handler
lastOverheadIndex <- max(c(0, which(isOverheadCall)))

trIdx <- rlang::seq2(lastOverheadIndex + 1, errorHandlerIndex-1)

err$trace <- rlang_trace_slice(tr, trIdx)
}
return(err)
}

# Copied from rlang:::trace_slice
rlang_trace_slice <- function (trace, i) {
i <- vctrs::vec_as_location(i, nrow(trace))
parent <- match(trace$parent, i, nomatch = 0)
out <- vctrs::vec_slice(trace, i)
out$parent <- parent[i]
out
}

# Copied from evaluate:::render
evaluate_render <- function(x){
if (isS4(x)) methods::show(x) else print(x)
}
2 changes: 1 addition & 1 deletion R/github.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ github_prefix <- "ocpu_github"
getlocaldir <- function(which = 'data'){
if(is_rapache() || is_admin()){
return("/usr/local/lib/opencpu")
} else if(getRversion() < 4){
} else if(getRversion() < "4"){
rappdirs::user_data_dir('opencpu')
} else {
tools::R_user_dir('opencpu', which)
Expand Down
1 change: 1 addition & 0 deletions R/httpget_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ httpget_info <- function(requri){
);
}

#' @export
print.opencpu_info <- function(x, ...){
titles <- names(x)
type <- ifelse(is_rapache(), "Cloud", "Single-User")
Expand Down
12 changes: 6 additions & 6 deletions R/httpget_webhook.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ httpget_webhook <- function(){

#Post-Receive data
gitref <- payload$ref;
giturl <- payload$repository$url;
giturl <- payload$repository$clone_url;
gitrepo <- payload$repository$name;
gitmaster <- payload$repository$master_branch;
gitmain <- payload$repository$default_branch;
gituser <- tolower(payload$repository$owner$name);

#Ignore all but master
if(is.null(gitref) || is.na(gitref) || !length(gitref) || gitref != paste0("refs/heads/", gitmaster)){
res$sendtext(sprintf("Ignoring non-master: %s (default/master branch is '%s')", gitref, gitmaster))
if(is.null(gitref) || is.na(gitref) || !length(gitref) || gitref != paste0("refs/heads/", gitmain)){
res$sendtext(sprintf("Ignoring non-main: %s (default/master branch is '%s')", gitref, gitmain))
}

#Check for gihtub
if(!grepl("^https://github.com", giturl)){
stop("Currently only Github CI is supported.");
stop("Currently only Github CI is supported. Found: ", giturl);
}

#trigger install and email
do.call(webhook_install, c(list(payload = payload), repo = gitrepo, username = gituser, ref = gitmaster, req$get()))
do.call(webhook_install, c(list(payload = payload), repo = gitrepo, username = gituser, ref = gitmain, req$get()))
}


Expand Down
6 changes: 4 additions & 2 deletions R/parse_post.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ parse_post <- function(reqbody, contenttype){
}

return(lapply(obj, function(x){
if(is.null(x) || isTRUE(is.atomic(x) && length(x) == 1 && !length(dim(x)))){
if(is.null(x) ||
isTRUE(is.atomic(x) && length(x) == 1 &&
!length(dim(x))) && is.null(names(x))){
#primitives as expressions
return(deparse_atomic(x))
} else {
Expand All @@ -66,7 +68,7 @@ parse_post <- function(reqbody, contenttype){

# base::deparse() fucks up utf8 strings
deparse_atomic <- function(x){
if(is.character(x)){
if(is.character(x) && !is.na(x)){
str <- jsonlite::toJSON(x)
str <- sub("^\\[", "c(", str)
sub("\\]$", ")", str)
Expand Down
13 changes: 1 addition & 12 deletions R/start.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ocpu_start_server <- function(port = 5656, root ="/ocpu", workers = 2, preload =
add_workers <- function(n = 1){
if(length(pool) < workers){
log("Starting %d new worker(s). Preloading: %s", n, paste(preload, collapse = ", "))
cl <- makeCluster(n)
cl <- parallel::makeCluster(n)
lapply(cl, sendCall, fun = function(){
lapply(preload, getNamespace)
Sys.getpid()
Expand Down Expand Up @@ -195,14 +195,3 @@ ocpu_start_app <- function(app, update = TRUE, ...){
start_local_app_local(app, ...)
}
}

## WORKAROUND: https://github.com/rstudio/rstudio/issues/6692
## Use 'sequential' setup of PSOCK cluster in RStudio Console on macOS and R 4.0.0
makeCluster <- function(..., setup_strategy = NULL){
if (Sys.getenv("RSTUDIO") == "1" && !nzchar(Sys.getenv("RSTUDIO_TERM")) &&
Sys.info()["sysname"] == "Darwin" && getRversion() >= "4") {
parallel::makeCluster(..., setup_strategy = "sequential")
} else {
parallel::makeCluster(...)
}
}
7 changes: 4 additions & 3 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,10 @@ deparse_query <- function(x){

format_user_error <- function(e){
errmsg <- e$message;
if(length(e$call)){
errmsg <- c(errmsg, "", "In call:", deparse(e$call));
}
if(length(e$call) && isTRUE(config("error.showcall")))
errmsg <- c(errmsg, "", "In call:", deparse(e$call), "")
if (length(e$trace) && length(e$trace$call) && isTRUE(config("error.backtrace")))
errmsg <- c(errmsg, "Backtrace:", format(e$trace))
return(errmsg)
}

Expand Down
5 changes: 1 addition & 4 deletions README.md
Loading