sfcheung/semptools

Allow `drop_nodes()` work with output from `lavaan::lavaanify()` without covariance input

marklhc opened this issue · 1 comments

Hi @sfcheung, I was using the semptools package and wanted to create a diagram just using lavaan syntax. The lavaanify() function allows converting syntax to a lavaan model object. I then ran into an error when using drop_nodes():

library(semptools)
m2 <- " eta_Y =~ 1 * fs_y
        eta_M =~ 1 * fs_m
        fs_y ~~ theta_y * fs_y
        fs_m ~~ theta_m * fs_m
        eta_Y ~ b2 * X + b3 * eta_M
        eta_M ~ b1 * X "
pm2 <- semPlot::semPlotModel(
    lavaan::lavaanify(m2)
)
pm2_2 <- drop_nodes(pm2, c("fs_y", "fs_m"))
#> Error in object@ObsCovs[[1]]: subscript out of bounds

Created on 2022-02-26 by the reprex package (v2.0.1)

Do you think we can make drop_nodes() change the ObsCovs and the ImpCovs slots only when the input semPlotModel contains those? I've added two conditional statements in a separate branch if you think it's okay to merge. Thanks!

Mark

@marklhc , thanks for your help! I merged your change to both the devel branch and the master branch. I also added a test and updated the version number.