diff --git a/NEWS b/NEWS index 0adf8e7..a9a76bd 100644 --- a/NEWS +++ b/NEWS @@ -3,9 +3,9 @@ `data` argument of `compileDecisionModel`. * Adds `factorFormula` to assist in writing formulae that make use of factor levels instead of their numeric codes. +* Deterministic nodes are now represented as diamonds by default. ### 0.10.0 (26 Sept 2015) ->>>>>>> origin/current-devel * Implements the `factorLevels` element in network objects and arguments in `setNode`. See Issue #81 * Changes to `plot.HydeNetwork` relevant to changes in diff --git a/R/factorFormula.R b/R/factorFormula.R index d0044ed..c241655 100644 --- a/R/factorFormula.R +++ b/R/factorFormula.R @@ -40,10 +40,12 @@ #' factorFormula <- function(form, network){ form <- deparse(form) + form <- trimws(form) + form <- paste0(form, collapse = "") relabel <- extractFactors(form) - relabel_mat <- isolateVariableFromLabel(relabel) + relabel_mat <- isolateVariableFromLabel(relabel, network) new_label <- mapply(getNumericLevel, @@ -73,7 +75,7 @@ extractFactors <- function(form){ unlist(relabel) } -isolateVariableFromLabel <- function(relabel){ +isolateVariableFromLabel <- function(relabel, network){ relabel_mat <- stringr::str_split_fixed(relabel, "[=][=]", 2) relabel_mat <- trimws(relabel_mat) relabel_mat <- gsub("('|\")", "", relabel_mat) diff --git a/vignettes/DecisionNetworks.Rmd b/vignettes/DecisionNetworks.Rmd index 56a72e4..1697209 100644 --- a/vignettes/DecisionNetworks.Rmd +++ b/vignettes/DecisionNetworks.Rmd @@ -288,23 +288,24 @@ net <- setNode(net, payoff, "determ", define=fromFormula(), nodeFormula = factorFormula(payoff ~ ifelse(playerFinalPoints > 21, -1, ifelse(playerFinalPoints == 21, - ifelse(dealerOutcome == 1, 0, + ifelse(dealerOutcome == "Blackjack", 0, ifelse(dealerOutcome == 7, 0, 1)), - ifelse(dealerOutcome == 2, + ifelse(dealerOutcome == "Bust", ifelse(playerFinalPoints < 22, 1, -1), - ifelse(dealerOutcome == 3, + ifelse(dealerOutcome == "17", ifelse(playerFinalPoints == 17, 0, ifelse(playerFinalPoints > 17, 1, -1)), - ifelse(dealerOutcome == 4, + ifelse(dealerOutcome == "18", ifelse(playerFinalPoints == 18, 0, ifelse(playerFinalPoints > 18, 1, -1)), - ifelse(dealerOutcome == 5, + ifelse(dealerOutcome == "19", ifelse(playerFinalPoints == 19, 0, ifelse(playerFinalPoints > 19, 1, -1)), - ifelse(dealerOutcome == 6, + ifelse(dealerOutcome == "20", ifelse(playerFinalPoints == 20, 0, ifelse(playerFinalPoints > 20, 1, -1)), - ifelse(playerFinalPoints == 21, 0, -1)))))))))) + ifelse(playerFinalPoints == 21, 0, -1)))))))), + net)) ```