Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically call optionContainsValue for elements <>.types #153

Closed
Closed
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
3 changes: 3 additions & 0 deletions R/common.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ runJaspResults <- function(name, title, dataKey, options, stateKey, functionCall
# ensure an analysis always starts with a clean hashtable of computed jasp Objects
emptyRecomputed()

# hack to add types automatically as dependencies, used in jaspObjectR$dependOn
options("__JASP__OPTIONS" = options)

analysisResult <-
tryCatch(
expr=withCallingHandlers(expr=analysis(jaspResults=jaspResults, dataset=dataset, options=options), error=.addStackTrace),
Expand Down
28 changes: 26 additions & 2 deletions R/zzzWrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,37 @@ jaspObjR <- R6::R6Class(
if (!is.null(optionContainsValue)) {
if (!is.list(optionContainsValue) || is.null(names(optionContainsValue)))
stop("please provide a named list in `optionContainsValue`", domain = NA)

# would be nicer to extract this from jaspResults somehow
completeOptions <- getOption("__JASP__OPTIONS", NULL)
meta <- completeOptions[[".meta"]]

for (i in seq_along(optionContainsValue)) {
name <- names(optionContainsValue)[i]
value <- optionContainsValue[[i]]

if (is.null(value))
stop("Expected not-null but got null")
private$jaspObject$setOptionMustContainDependency(name, value)

# if we have something of the form list(variables = variable)
# check if we need to add also list(variables.types = type)
if (!is.null(meta)) {
nameType <- paste0(name, ".types")
if (isTRUE(meta[[name]][["hasTypes"]]) &&
!is.null(completeOptions[[nameType]])) {
completeOptionsValue <- completeOptions[[name]]
completeOptionsTypes <- completeOptions[[nameType]]
idx <- which(completeOptionsValue == value)
if (length(idx) > 0L) {
valueType <- completeOptionsTypes[[idx[[1L]]]] # take first element in case there are multiple matches (which should be impossible)
# for debugging
# cat(sprintf("Automatically added setOptionMustContainDependency(%s, %s)\n", nameType, valueType))
private$jaspObject$setOptionMustContainDependency(nameType, valueType)
}
}
}

}
}

Expand Down Expand Up @@ -824,7 +848,7 @@ jaspColumnR <- R6::R6Class(
inherit = jaspOutputObjR,
cloneable = FALSE,
public = list(
initialize = function(columnName="", dependencies=NULL, scalarData=NULL, ordinalData=NULL, nominalData=NULL, nominalTextData=NULL, info=NULL, jaspObject = NULL)
initialize = function(columnName="", dependencies=NULL, scalarData=NULL, ordinalData=NULL, nominalData=NULL, nominalTextData=NULL, info=NULL, jaspObject = NULL)
{
if (!is.null(jaspObject)) {
private$jaspObject <- jaspObject
Expand All @@ -848,7 +872,7 @@ jaspColumnR <- R6::R6Class(

return()
},

setScale = function(scalarData) private$jaspObject$setScale(scalarData),
setOrdinal = function(ordinalData) private$jaspObject$setOrdinal(ordinalData),
setNominal = function(nominalData) private$jaspObject$setNominal(nominalData),
Expand Down
Loading