From 2af17a616cac712591b4c09ee147fead39c33741 Mon Sep 17 00:00:00 2001 From: Shu Fai Cheung Date: Sun, 20 Jul 2025 13:27:53 +0800 Subject: [PATCH 1/2] 0.3.2.1: Update to better detect manifest and latent variables Tests, checks, and build_site() passed. --- DESCRIPTION | 2 +- NEWS.md | 9 +++++++++ R/helpers.R | 12 ++++++------ R/set_sem_layout.R | 21 +++++++++++++-------- README.md | 2 +- 5 files changed, 30 insertions(+), 16 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ff94d13..07129be 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: semptools Title: Customizing Structural Equation Modelling Plots -Version: 0.3.2 +Version: 0.3.2.1 Authors@R: c( person(given = "Shu Fai", family = "Cheung", diff --git a/NEWS.md b/NEWS.md index 1e1e6ee..49e6655 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,12 @@ +# semptools 0.3.2.1 + +## Improvement + +- Updated to treat rectangles as + manifest variables and ellipses as + latent variables + (0.3.2.1) + # semptools 0.3.2 ## New Features diff --git a/R/helpers.R b/R/helpers.R index 8b63c7d..9680ff0 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -9,22 +9,22 @@ node_plot <- function(semPaths_plot) { man_plot <- function(semPaths_plot) { nodes <- semPaths_plot$graphAttributes$Nodes - nodes$names[nodes$shape == "square"] + nodes$names[nodes$shape == "square"] | nodes$names[nodes$shape == "rectangle"] } #' @noRd lat_plot <- function(semPaths_plot) { nodes <- semPaths_plot$graphAttributes$Nodes - nodes$names[nodes$shape == "circle"] + nodes$names[nodes$shape == "circle"] | nodes$names[nodes$shape == "ellipse"] } #' @noRd indicator_plot <- function(semPaths_plot) { nodes <- semPaths_plot$graphAttributes$Nodes - man_id <- which(nodes$shape == "square") - lat_id <- which(nodes$shape == "circle") + man_id <- which((nodes$shape == "square") | (nodes$shape == "rectangle")) + lat_id <- which((nodes$shape == "circle") | (nodes$shape == "ellipse")) edges <- as.data.frame(semPaths_plot$Edgelist) edges2 <- edges[edges$directed & !edges$bidirectional, ] id <- (edges2$from %in% lat_id) & (edges2$to %in% man_id) @@ -39,8 +39,8 @@ loading_plot <- function(semPaths_plot, # Assume that: # squares are manifest variables # circles are latent variables - man_id <- which(nodes$shape == "square") - lat_id <- which(nodes$shape == "circle") + man_id <- which((nodes$shape == "square") | (nodes$shape == "rectangle")) + lat_id <- which((nodes$shape == "circle") | (nodes$shape == "ellipse")) edges <- as.data.frame(semPaths_plot$Edgelist) edges2 <- edges[edges$directed & !edges$bidirectional, ] id <- (edges2$from %in% lat_id) & (edges2$to %in% man_id) diff --git a/R/set_sem_layout.R b/R/set_sem_layout.R index a115563..d3d592c 100644 --- a/R/set_sem_layout.R +++ b/R/set_sem_layout.R @@ -280,10 +280,11 @@ set_sem_layout <- function(semPaths_plot, } else { Nodes_names2 <- NA } - - if (!all(Nodes_names[semPaths_plot$graphAttributes$Nodes$shape == "square"] %in% indicator_order)) { - if (!all(Nodes_names2[semPaths_plot$graphAttributes$Nodes$shape == "square"] %in% indicator_order)) { - tmp1 <- Nodes_names2[semPaths_plot$graphAttributes$Nodes$shape == "square"] + tmp0 <- semPaths_plot$graphAttributes$Nodes$shape == "square" | + semPaths_plot$graphAttributes$Nodes$shape == "rectangle" + if (!all(Nodes_names[tmp0] %in% indicator_order)) { + if (!all(Nodes_names2[tmp0] %in% indicator_order)) { + tmp1 <- Nodes_names2[tmp0] tmp2 <- indicator_order msg_tmp <- setdiff(tmp1, indicator_order) @@ -299,8 +300,10 @@ set_sem_layout <- function(semPaths_plot, indicator_order <- tmp } } - if (!all(Nodes_names[semPaths_plot$graphAttributes$Nodes$shape == "circle"] %in% indicator_factor)) { - if (!all(Nodes_names2[semPaths_plot$graphAttributes$Nodes$shape == "circle"] %in% indicator_factor)) { + tmp0 <- (semPaths_plot$graphAttributes$Nodes$shape == "circle") | + (semPaths_plot$graphAttributes$Nodes$shape == "ellipse") + if (!all(Nodes_names[tmp0] %in% indicator_factor)) { + if (!all(Nodes_names2[tmp0] %in% indicator_factor)) { warning("One or more factors in the graph are not in indicator_factor. Unexpected results may occur.") } else { tmp <- sapply(indicator_factor, function(x) { @@ -320,10 +323,12 @@ set_sem_layout <- function(semPaths_plot, # if (!all(Nodes_names[semPaths_plot$graphAttributes$Nodes$shape == "circle"] %in% indicator_factor)) { # warning("One or more factors in the graph may not be in indicator_factor. Unexpected results may occur.") # } + tmp0 <- (semPaths_plot$graphAttributes$Nodes$shape == "circle") | + (semPaths_plot$graphAttributes$Nodes$shape == "ellipse") if (!all(indicator_factor %in% factor_layout[!is.na(factor_layout)])) { - if (!all(Nodes_names2[semPaths_plot$graphAttributes$Nodes$shape == "circle"] %in% + if (!all(Nodes_names2[tmp0] %in% factor_layout[!is.na(factor_layout)])) { - tmp <- Nodes_names2[semPaths_plot$graphAttributes$Nodes$shape == "circle"] + tmp <- Nodes_names2[tmp0] msg_tmp <- setdiff(tmp, factor_layout[!is.na(factor_layout)]) msg_tmp <- paste(unlist(msg_tmp), diff --git a/README.md b/README.md index f438fe1..f798538 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ [![R-CMD-check](https://github.com/sfcheung/semptools/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/sfcheung/semptools/actions/workflows/R-CMD-check.yaml) -(Version 0.3.2, updated on 2025-07-12, [release history](https://sfcheung.github.io/semptools/news/index.html)) +(Version 0.3.2.1, updated on 2025-07-20, [release history](https://sfcheung.github.io/semptools/news/index.html)) # semptools From a7eb4a2a822b8ea931faf49908ccf230a0150456 Mon Sep 17 00:00:00 2001 From: Shu Fai Cheung Date: Sun, 20 Jul 2025 13:35:23 +0800 Subject: [PATCH 2/2] Temporarily disable the test on oldrel --- .github/workflows/R-CMD-check.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 27266e7..f76ab0f 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -22,7 +22,8 @@ jobs: - {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'} + # Temporarily disabled due to OpenMx's dependence on R 4.5.0 + # - {os: ubuntu-latest, r: 'oldrel-1'} - {os: ubuntu-latest, r: 'release', nosuggests: true, special: "No Suggests"} env: