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

semPaths(..., nCharNodes = 0) does not give labels in a named vector, causing an error when calling set_cfa_layout() after change_node_label() #59

Closed
marklhc opened this issue Dec 31, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@marklhc
Copy link
Collaborator

marklhc commented Dec 31, 2020

As illustrated below, semPaths() gives a named vector for the labels without specifying nCharNodes, but gives an unnamed vector when nCharNodes = 0.

library(lavaan)
#> This is lavaan 0.6-7
#> lavaan is BETA software! Please report any bugs.
library(semPlot)
#> Registered S3 methods overwritten by 'huge':
#>   method    from   
#>   plot.sim  BDgraph
#>   print.sim BDgraph
library(semptools)

mod_pa <- 
  'x1 ~~ x2
   x3 ~  x1 + x2
   x4 ~  x1 + x3
  '
fit_pa <- lavaan::sem(mod_pa, pa_example)
# Use custom labels
m <- matrix(c("x1",   NA,  NA,   NA,
              NA, "x3",  NA, "x4",
              "x2",   NA,  NA,   NA), byrow = TRUE, 3, 4)
p_pa <- semPaths(fit_pa, whatLabels = "est",
                 sizeMan = 10,
                 edge.label.cex = 1.15,
                 layout = m)

p_pa$graphAttributes$Nodes$labels
#>   x3   x4   x1   x2 
#> "x3" "x4" "x1" "x2"

p_pa2 <- semPaths(fit_pa,
  whatLabels = "est",
  nCharNodes = 0, 
  sizeMan = 10,
  edge.label.cex = 1.15,
  layout = m
)

p_pa2$graphAttributes$Nodes$labels
#> [1] "x3" "x4" "x1" "x2"

Created on 2020-12-31 by the reprex package (v0.3.0)

This causes an issue as when the labels are not named, the labels after applying change_node_labels() will also be unnamed, and the original variable names are lost, causing set_cfa_layout() and set_sem_layout() to fail.

A solution is to modify change_node_labels() to add the original labels as names when the original labels is an unnamed vector. I've made the changes and will push to a new branch before merging.

marklhc added a commit that referenced this issue Dec 31, 2020
@sfcheung sfcheung added this to To do in semptools_project May 18, 2021
@sfcheung sfcheung added the bug Something isn't working label Jul 27, 2021
@sfcheung
Copy link
Owner

sfcheung commented Aug 2, 2021

I checked and this problem should have been fixed in. See test-change-node.R and bfc4ab6.

@sfcheung sfcheung closed this as completed Aug 2, 2021
semptools_project automation moved this from To do to Done Aug 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

No branches or pull requests

2 participants