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
4 changes: 3 additions & 1 deletion R/common.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,15 @@ runJaspResults <- function(name, title, dataKey, options, stateKey, functionCall

# ensure an analysis always starts with a clean hashtable of computed jasp Objects
emptyRecomputed()
emptyWarnings()

analysisResult <-
tryCatch(
expr=withCallingHandlers(expr=analysis(jaspResults=jaspResults, dataset=dataset, options=options), error=.addStackTrace),
expr=withCallingHandlers(expr=analysis(jaspResults=jaspResults, dataset=dataset, options=options), error=.addStackTrace, warning = .addWarnings),
error=function(e) e,
jaspAnalysisAbort=function(e) e
)
.appendOutputFromR(jaspResults)

if (!jaspResultsCalledFromJasp()) {

Expand Down
31 changes: 31 additions & 0 deletions R/commonerrorcheck.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,37 @@
signalCondition(e)
}

.addWarnings <- function(w) {
.internal[["warnings"]] <- c(.internal[["warnings"]], list(w))
}

.appendOutputFromR <- function(container) {
warnings <- .internal[["warnings"]]
# display only in developer mode
# currently adds only warnings, do we also want messages or something?
if (!getDeveloperMode() || identical(warnings, list())) return()

output <- createJaspContainer(title = gettext("Output from R"), initCollapsed = TRUE)

# Adds a warning element to a jaspContainer
text <- vapply(warnings, function(w) {
# oh lord forgive me for the code I am about to write right now:
# as.character can produce special symbols that are used to render the text in a different format in the R console, so the warning may become unintelligible
# so instead we `cat()` the output which prints the formatted text
# and capture the output as text again (without formatting)
w <- capture.output(cat(as.character(w)))
w <- paste0(w, collapse = "<br>")
return(w)
}, character(1))

text <- paste0("<li><p class='jasp-code'>", text, "</p></li>", collapse = "")
text <- paste0("<ul>", text, "</ul>")

output[["warnings"]] <- createJaspHtml(title = gettext("Warnings"), text = text)

container[[".outputFromR"]] <- output
}


.generateErrorMessage <- function(type, opening=FALSE, concatenate=NULL, grouping=NULL, ...) {
# Generic function to create an error message (mostly used by .hasErrors() but it can be called directly).
Expand Down
7 changes: 6 additions & 1 deletion R/setOrRetrieve.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# It's not 100% clear if "address" is the best choice here, but it should be a little bit faster than constructing hashes using identical.
# See also https://github.com/wch/r-source/blob/trunk/src/library/utils/src/hashtab.c
recomputedHashtab = hashtab(type = "address", NULL),
lastRecomputed = TRUE
lastRecomputed = TRUE,
warnings = list()
), parent = emptyenv())

saveHashOfJaspObject <- function(x) {
Expand All @@ -20,6 +21,10 @@ emptyRecomputed <- function() {
setRecomputed(TRUE)
}

emptyWarnings <- function() {
.internal[["warnings"]] <- list()
}

#' Set or retrieve a jaspObject
#' @description `%setOrRetrieve%` is a useful shorthand for a common pattern.
#' @param lhs an assignment into a jaspObject, e.g., `container[["table"]]`.
Expand Down
1 change: 1 addition & 0 deletions src/jaspModuleRegistration.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ RCPP_MODULE(jaspResults)
Rcpp::function("writeSealFilename", jaspResults::writeSealFilename);
Rcpp::function("setResponseData", jaspResults::setResponseData);
Rcpp::function("setDeveloperMode", jaspResults::setDeveloperMode);
Rcpp::function("getDeveloperMode", jaspResults::getDeveloperMode);
Rcpp::function("setSaveLocation", jaspResults::setSaveLocation);
Rcpp::function("setWriteSealLocation", jaspResults::setWriteSealLocation);

Expand Down
5 changes: 5 additions & 0 deletions src/jaspObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,11 @@ void jaspObject::setDeveloperMode(bool developerMode)
_developerMode = developerMode;
}

bool jaspObject::getDeveloperMode()
{
return _developerMode;
}

bool jaspObject::connectedToJaspResults()
{

Expand Down
1 change: 1 addition & 0 deletions src/jaspObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class jaspObject

static int getCurrentTimeMs();
static void setDeveloperMode(bool developerMode);
static bool getDeveloperMode();

bool connectedToJaspResults();

Expand Down