rempsyc / lavaanExtra

Convenience Functions for Package `lavaan`
https://lavaanExtra.remi-theriault.com/
Other
19 stars 4 forks source link

Please make `DiagrammeRsvg` optional for running tests #35

Closed barracuda156 closed 1 month ago

barracuda156 commented 1 month ago

Currently tests will fail if DiagrammeRsvg not installed:

--->  Testing R-lavaanExtra
Executing:  cd "/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_R_R-lavaanExtra/R-lavaanExtra/work/lavaanExtra-0.2.0" && /opt/local/bin/R CMD check ./lavaanExtra_0.2.0.tar.gz --no-manual --no-build-vignettes 
* using log directory ‘/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_R_R-lavaanExtra/R-lavaanExtra/work/lavaanExtra-0.2.0/lavaanExtra.Rcheck’
* using R version 4.4.0 (2024-04-24)
* using platform: powerpc-apple-darwin10.0.0d2 (32-bit)
* R was compiled by
    gcc-mp-13 (MacPorts gcc13 13.2.0_4+stdlib_flag) 13.2.0
    GNU Fortran (MacPorts gcc13 13.2.0_4+stdlib_flag) 13.2.0
* running under: OS X Snow Leopard 10.6
* using session charset: UTF-8
* using options ‘--no-manual --no-build-vignettes’
* checking for file ‘lavaanExtra/DESCRIPTION’ ... OK
* this is package ‘lavaanExtra’ version ‘0.2.0’
* package encoding: UTF-8
* checking package namespace information ... OK
* checking package dependencies ... NOTE
Package suggested but not available for checking: ‘DiagrammeRsvg’
* checking if this is a source package ... OK
* checking if there is a namespace ... OK
* checking for executable files ... OK
* checking for hidden files and directories ... OK
* checking for portable file names ... OK
* checking for sufficient/correct file permissions ... OK
* checking whether package ‘lavaanExtra’ can be installed ... OK
* checking installed package size ... OK
* checking package directory ... OK
* checking DESCRIPTION meta-information ... OK
* checking top-level files ... OK
* checking for left-over files ... OK
* checking index information ... OK
* checking package subdirectories ... OK
* checking code files for non-ASCII characters ... OK
* checking R files for syntax errors ... OK
* checking whether the package can be loaded ... OK
* checking whether the package can be loaded with stated dependencies ... OK
* checking whether the package can be unloaded cleanly ... OK
* checking whether the namespace can be loaded with stated dependencies ... OK
* checking whether the namespace can be unloaded cleanly ... OK
* checking whether startup messages can be suppressed ... OK
* checking dependencies in R code ... OK
* checking S3 generic/method consistency ... OK
* checking replacement functions ... OK
* checking foreign function calls ... OK
* checking R code for possible problems ... OK
* checking Rd files ... OK
* checking Rd metadata ... OK
* checking Rd cross-references ... OK
* checking for missing documentation entries ... OK
* checking for code/documentation mismatches ... OK
* checking Rd \usage sections ... OK
* checking Rd contents ... OK
* checking for unstated dependencies in examples ... OK
* checking files in ‘vignettes’ ... WARNING
Files in the 'vignettes' directory but no files in 'inst/doc':
  ‘example.Rmd’ ‘write_lavaan.Rmd’
* checking examples ... ERROR
Running examples in ‘lavaanExtra-Ex.R’ failed
The error most likely occurred in:

> ### Name: cfa_fit_plot
> ### Title: Fit and plot CFA simultaneously
> ### Aliases: cfa_fit_plot
> 
> ### ** Examples
> 
> ## Don't show: 
> if (requireNamespace("lavaan", quietly = TRUE) && requireNamespace("lavaanPlot", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)({ # examplesIf
+ ## End(Don't show)
+ x <- paste0("x", 1:9)
+ (latent <- list(
+   visual = x[1:3],
+   textual = x[4:6],
+   speed = x[7:9]
+ ))
+ 
+ HS.model <- write_lavaan(latent = latent)
+ cat(HS.model)
+ 
+ library(lavaan)
+ fit <- cfa_fit_plot(HS.model, HolzingerSwineford1939)
+ ## Don't show: 
+ }) # examplesIf
> x <- paste0("x", 1:9)
> (latent <- list(visual = x[1:3], textual = x[4:6], speed = x[7:9]))
$visual
[1] "x1" "x2" "x3"

$textual
[1] "x4" "x5" "x6"

$speed
[1] "x7" "x8" "x9"

> HS.model <- write_lavaan(latent = latent)
> cat(HS.model)
##################################################
# [-----Latent variables (measurement model)-----]

visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9

> library(lavaan)
This is lavaan 0.6-18
lavaan is FREE software! Please report any bugs.
> fit <- cfa_fit_plot(HS.model, HolzingerSwineford1939)
lavaan 0.6-18 ended normally after 35 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                        21

  Number of observations                           301

Model Test User Model:
                                              Standard      Scaled
  Test Statistic                                85.306      87.132
  Degrees of freedom                                24          24
  P-value (Chi-square)                           0.000       0.000
  Scaling correction factor                                  0.979
    Yuan-Bentler correction (Mplus variant)                       

Model Test Baseline Model:

  Test statistic                               918.852     880.082
  Degrees of freedom                                36          36
  P-value                                        0.000       0.000
  Scaling correction factor                                  1.044

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.931       0.925
  Tucker-Lewis Index (TLI)                       0.896       0.888

  Robust Comparative Fit Index (CFI)                         0.930
  Robust Tucker-Lewis Index (TLI)                            0.895

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)              -3737.745   -3737.745
  Scaling correction factor                                  1.133
      for the MLR correction                                      
  Loglikelihood unrestricted model (H1)      -3695.092   -3695.092
  Scaling correction factor                                  1.051
      for the MLR correction                                      

  Akaike (AIC)                                7517.490    7517.490
  Bayesian (BIC)                              7595.339    7595.339
  Sample-size adjusted Bayesian (SABIC)       7528.739    7528.739

Root Mean Square Error of Approximation:

  RMSEA                                          0.092       0.093
  90 Percent confidence interval - lower         0.071       0.073
  90 Percent confidence interval - upper         0.114       0.115
  P-value H_0: RMSEA <= 0.050                    0.001       0.001
  P-value H_0: RMSEA >= 0.080                    0.840       0.862

  Robust RMSEA                                               0.092
  90 Percent confidence interval - lower                     0.072
  90 Percent confidence interval - upper                     0.114
  P-value H_0: Robust RMSEA <= 0.050                         0.001
  P-value H_0: Robust RMSEA >= 0.080                         0.849

Standardized Root Mean Square Residual:

  SRMR                                           0.065       0.065

Parameter Estimates:

  Standard errors                             Sandwich
  Information bread                           Observed
  Observed information based on                Hessian

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  visual =~                                                             
    x1                1.000                               0.900    0.772
    x2                0.554    0.132    4.191    0.000    0.498    0.424
    x3                0.729    0.141    5.170    0.000    0.656    0.581
  textual =~                                                            
    x4                1.000                               0.990    0.852
    x5                1.113    0.066   16.946    0.000    1.102    0.855
    x6                0.926    0.061   15.089    0.000    0.917    0.838
  speed =~                                                              
    x7                1.000                               0.619    0.570
    x8                1.180    0.130    9.046    0.000    0.731    0.723
    x9                1.082    0.266    4.060    0.000    0.670    0.665

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  visual ~~                                                             
    textual           0.408    0.099    4.110    0.000    0.459    0.459
    speed             0.262    0.060    4.366    0.000    0.471    0.471
  textual ~~                                                            
    speed             0.173    0.056    3.081    0.002    0.283    0.283

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .x1                0.549    0.156    3.509    0.000    0.549    0.404
   .x2                1.134    0.112   10.135    0.000    1.134    0.821
   .x3                0.844    0.100    8.419    0.000    0.844    0.662
   .x4                0.371    0.050    7.382    0.000    0.371    0.275
   .x5                0.446    0.057    7.870    0.000    0.446    0.269
   .x6                0.356    0.047    7.658    0.000    0.356    0.298
   .x7                0.799    0.097    8.222    0.000    0.799    0.676
   .x8                0.488    0.120    4.080    0.000    0.488    0.477
   .x9                0.566    0.119    4.768    0.000    0.566    0.558
    visual            0.809    0.180    4.486    0.000    1.000    1.000
    textual           0.979    0.121    8.075    0.000    1.000    1.000
    speed             0.384    0.107    3.596    0.000    1.000    1.000

R-Square:
                   Estimate
    x1                0.596
    x2                0.179
    x3                0.338
    x4                0.725
    x5                0.731
    x6                0.702
    x7                0.324
    x8                0.523
    x9                0.442

Error: Package `DiagrammeRsvg` required for this function..
  Please install it by running `install.packages("DiagrammeRsvg")`.
Execution halted
* checking for unstated dependencies in ‘tests’ ... OK
* checking tests ...
  Running ‘spelling.R’
  Running ‘testthat.R’
 ERROR
Running the tests in ‘tests/testthat.R’ failed.
Last 13 lines of output:
   5.   └─insight::check_if_installed(...)
  ── Error ('test-nice_lavaanPlot.R:72:3'): nice_lavaanPlot different sem model ──
  Error: Package `DiagrammeRsvg` required for this function..
    Please install it by running `install.packages("DiagrammeRsvg")`.
  Backtrace:
      ▆
   1. ├─testthat::expect_s3_class(...) at test-nice_lavaanPlot.R:72:3
   2. │ └─testthat::quasi_label(enquo(object), arg = "object")
   3. │   └─rlang::eval_bare(expr, quo_get_env(quo))
   4. └─lavaanExtra::nice_lavaanPlot(fit.sem2)
   5.   └─insight::check_if_installed(...)

  [ FAIL 6 | WARN 0 | SKIP 23 | PASS 32 ]
  Error: Test failures
  Execution halted
* checking for unstated dependencies in vignettes ... OK
* checking package vignettes ... WARNING
Directory 'inst/doc' does not exist.
Package vignettes without corresponding single PDF/HTML:
  ‘example.Rmd’
  ‘write_lavaan.Rmd’
* checking running R code from vignettes ...
  ‘example.Rmd’ using ‘UTF-8’... OK
  ‘write_lavaan.Rmd’ using ‘UTF-8’... OK
 OK
* checking re-building of vignette outputs ... SKIPPED
* DONE

Status: 2 ERRORs, 2 WARNINGs, 1 NOTE
See
  ‘/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_R_R-lavaanExtra/R-lavaanExtra/work/lavaanExtra-0.2.0/lavaanExtra.Rcheck/00check.log’
for details.

Command failed:  cd "/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_R_R-lavaanExtra/R-lavaanExtra/work/lavaanExtra-0.2.0" && /opt/local/bin/R CMD check ./lavaanExtra_0.2.0.tar.gz --no-manual --no-build-vignettes 
Exit code: 1

However, unfortunately, DiagrammeRsvg depends on V8, which is unjustifiedly heavy dependency to build and also broken on some platforms.

barracuda156 commented 1 month ago

R version 4.4.0 (2024-04-24) -- "Puppy Cup"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: powerpc-apple-darwin10.0.0d2 (32-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> # This file is part of the standard setup for testthat.
> # It is recommended that you do not modify it.
> #
> # Where should you do additional test configuration?
> # Learn more about the roles of various files in:
> # * https://r-pkgs.org/tests.html
> # * https://testthat.r-lib.org/reference/test_package.html#special-files
> 
> library(testthat)
> library(lavaanExtra)
Suggested APA citation: Thériault, R. (2023). lavaanExtra: Convenience functions for lavaan. 
Journal of Open Source Software, 8(90), 5701. https://doi.org/10.21105/joss.05701
> 
> test_check("lavaanExtra")
This is lavaan 0.6-18
lavaan is FREE software! Please report any bugs.
lavaan 0.6-18 ended normally after 35 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                        21

  Number of observations                           301

Model Test User Model:
                                              Standard      Scaled
  Test Statistic                                85.306      87.132
  Degrees of freedom                                24          24
  P-value (Chi-square)                           0.000       0.000
  Scaling correction factor                                  0.979
    Yuan-Bentler correction (Mplus variant)                       

Model Test Baseline Model:

  Test statistic                               918.852     880.082
  Degrees of freedom                                36          36
  P-value                                        0.000       0.000
  Scaling correction factor                                  1.044

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.931       0.925
  Tucker-Lewis Index (TLI)                       0.896       0.888

  Robust Comparative Fit Index (CFI)                         0.930
  Robust Tucker-Lewis Index (TLI)                            0.895

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)              -3737.745   -3737.745
  Scaling correction factor                                  1.133
      for the MLR correction                                      
  Loglikelihood unrestricted model (H1)      -3695.092   -3695.092
  Scaling correction factor                                  1.051
      for the MLR correction                                      

  Akaike (AIC)                                7517.490    7517.490
  Bayesian (BIC)                              7595.339    7595.339
  Sample-size adjusted Bayesian (SABIC)       7528.739    7528.739

Root Mean Square Error of Approximation:

  RMSEA                                          0.092       0.093
  90 Percent confidence interval - lower         0.071       0.073
  90 Percent confidence interval - upper         0.114       0.115
  P-value H_0: RMSEA <= 0.050                    0.001       0.001
  P-value H_0: RMSEA >= 0.080                    0.840       0.862

  Robust RMSEA                                               0.092
  90 Percent confidence interval - lower                     0.072
  90 Percent confidence interval - upper                     0.114
  P-value H_0: Robust RMSEA <= 0.050                         0.001
  P-value H_0: Robust RMSEA >= 0.080                         0.849

Standardized Root Mean Square Residual:

  SRMR                                           0.065       0.065

Parameter Estimates:

  Standard errors                             Sandwich
  Information bread                           Observed
  Observed information based on                Hessian

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  visual =~                                                             
    x1                1.000                               0.900    0.772
    x2                0.554    0.132    4.191    0.000    0.498    0.424
    x3                0.729    0.141    5.170    0.000    0.656    0.581
  textual =~                                                            
    x4                1.000                               0.990    0.852
    x5                1.113    0.066   16.946    0.000    1.102    0.855
    x6                0.926    0.061   15.089    0.000    0.917    0.838
  speed =~                                                              
    x7                1.000                               0.619    0.570
    x8                1.180    0.130    9.046    0.000    0.731    0.723
    x9                1.082    0.266    4.060    0.000    0.670    0.665

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  visual ~~                                                             
    textual           0.408    0.099    4.110    0.000    0.459    0.459
    speed             0.262    0.060    4.366    0.000    0.471    0.471
  textual ~~                                                            
    speed             0.173    0.056    3.081    0.002    0.283    0.283

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .x1                0.549    0.156    3.509    0.000    0.549    0.404
   .x2                1.134    0.112   10.135    0.000    1.134    0.821
   .x3                0.844    0.100    8.419    0.000    0.844    0.662
   .x4                0.371    0.050    7.382    0.000    0.371    0.275
   .x5                0.446    0.057    7.870    0.000    0.446    0.269
   .x6                0.356    0.047    7.658    0.000    0.356    0.298
   .x7                0.799    0.097    8.222    0.000    0.799    0.676
   .x8                0.488    0.120    4.080    0.000    0.488    0.477
   .x9                0.566    0.119    4.768    0.000    0.566    0.558
    visual            0.809    0.180    4.486    0.000    1.000    1.000
    textual           0.979    0.121    8.075    0.000    1.000    1.000
    speed             0.384    0.107    3.596    0.000    1.000    1.000

R-Square:
                   Estimate
    x1                0.596
    x2                0.179
    x3                0.338
    x4                0.725
    x5                0.731
    x6                0.702
    x7                0.324
    x8                0.523
    x9                0.442

[ FAIL 6 | WARN 0 | SKIP 23 | PASS 32 ]

══ Skipped tests (23) ══════════════════════════════════════════════════════════
• On CRAN (23): 'test-cfa_fit_plot.R:38:3', 'test-lavaan_defined.R:33:3',
  'test-lavaan_defined.R:41:3', 'test-lavaan_defined.R:63:3',
  'test-lavaan_defined.R:74:3', 'test-nice_modindices.R:35:3',
  'test-nice_modindices.R:42:3', 'test-nice_modindices.R:58:3',
  'test-write_lavaan.R:35:3', 'test-write_lavaan.R:39:3',
  'test-write_lavaan.R:43:3', 'test-write_lavaan.R:47:3',
  'test-write_lavaan.R:51:3', 'test-write_lavaan.R:55:3',
  'test-write_lavaan.R:63:3', 'test-write_lavaan.R:73:3',
  'test-write_lavaan.R:83:3', 'test-write_lavaan.R:87:3',
  'test-write_lavaan.R:91:3', 'test-write_lavaan.R:95:3',
  'test-write_lavaan.R:99:3', 'test-write_lavaan.R:103:3',
  'test-write_lavaan.R:107:3'

══ Failed tests ════════════════════════════════════════════════════════════════
── Error ('test-cfa_fit_plot.R:30:3'): cfa_fit_plot comparison to cfa ──────────
Error: Package `DiagrammeRsvg` required for this function..
  Please install it by running `install.packages("DiagrammeRsvg")`.
Backtrace:
    ▆
 1. └─lavaanExtra::cfa_fit_plot(model, data) at test-cfa_fit_plot.R:30:3
 2.   └─lavaanExtra::nice_lavaanPlot(fit, covs = covs)
 3.     └─insight::check_if_installed(...)
── Error ('test-cfa_fit_plot.R:52:3'): cfa_fit_plot remove items ───────────────
Error: Package `DiagrammeRsvg` required for this function..
  Please install it by running `install.packages("DiagrammeRsvg")`.
Backtrace:
    ▆
 1. └─lavaanExtra::cfa_fit_plot(model, data, print = FALSE, remove.items = c("x1")) at test-cfa_fit_plot.R:52:3
 2.   └─lavaanExtra::nice_lavaanPlot(fit, covs = covs)
 3.     └─insight::check_if_installed(...)
── Error ('test-nice_lavaanPlot.R:48:3'): nice_lavaanPlot on CFA ───────────────
Error: Package `DiagrammeRsvg` required for this function..
  Please install it by running `install.packages("DiagrammeRsvg")`.
Backtrace:
    ▆
 1. ├─testthat::expect_s3_class(...) at test-nice_lavaanPlot.R:48:3
 2. │ └─testthat::quasi_label(enquo(object), arg = "object")
 3. │   └─rlang::eval_bare(expr, quo_get_env(quo))
 4. └─lavaanExtra::nice_lavaanPlot(fit.cfa)
 5.   └─insight::check_if_installed(...)
── Error ('test-nice_lavaanPlot.R:56:3'): nice_lavaanPlot on SEM ───────────────
Error: Package `DiagrammeRsvg` required for this function..
  Please install it by running `install.packages("DiagrammeRsvg")`.
Backtrace:
    ▆
 1. ├─testthat::expect_s3_class(...) at test-nice_lavaanPlot.R:56:3
 2. │ └─testthat::quasi_label(enquo(object), arg = "object")
 3. │   └─rlang::eval_bare(expr, quo_get_env(quo))
 4. └─lavaanExtra::nice_lavaanPlot(fit.sem)
 5.   └─insight::check_if_installed(...)
── Error ('test-nice_lavaanPlot.R:64:3'): nice_lavaanPlot on lavaan ────────────
Error: Package `DiagrammeRsvg` required for this function..
  Please install it by running `install.packages("DiagrammeRsvg")`.
Backtrace:
    ▆
 1. ├─testthat::expect_s3_class(...) at test-nice_lavaanPlot.R:64:3
 2. │ └─testthat::quasi_label(enquo(object), arg = "object")
 3. │   └─rlang::eval_bare(expr, quo_get_env(quo))
 4. └─lavaanExtra::nice_lavaanPlot(fit.lavaan)
 5.   └─insight::check_if_installed(...)
── Error ('test-nice_lavaanPlot.R:72:3'): nice_lavaanPlot different sem model ──
Error: Package `DiagrammeRsvg` required for this function..
  Please install it by running `install.packages("DiagrammeRsvg")`.
Backtrace:
    ▆
 1. ├─testthat::expect_s3_class(...) at test-nice_lavaanPlot.R:72:3
 2. │ └─testthat::quasi_label(enquo(object), arg = "object")
 3. │   └─rlang::eval_bare(expr, quo_get_env(quo))
 4. └─lavaanExtra::nice_lavaanPlot(fit.sem2)
 5.   └─insight::check_if_installed(...)

[ FAIL 6 | WARN 0 | SKIP 23 | PASS 32 ]
Error: Test failures
Execution halted
rempsyc commented 1 month ago

Thank you for reporting! In the new version, the relevant tests and examples have been made conditional on the installation of DiagrammeRsvg. DiagrammeRsvg only seems necessary so that the pkgdown workflow doesn't fail. May I ask in which context you rely on lavaanExtra?

barracuda156 commented 2 weeks ago

@rempsyc Thank you!

I maintain R packages in MacPorts, and lavaanExtra is among those: https://ports.macports.org/port/R-lavaanExtra