@@ -121,6 +121,8 @@ test_that("do_cor should skip group with only one row.", {
121121})
122122
123123test_that(" do_cor with polychoric method" , {
124+ skip_if_not_installed(" polycor" )
125+
124126 # Polychoric correlation is for ordinal variables. The latent variables behind x and y
125127 # are correlated at 0.7, while z is independent of them.
126128 set.seed(123 )
@@ -168,6 +170,8 @@ test_that("do_cor supports automatic and mixed correlations with factor inputs",
168170})
169171
170172test_that(" do_cor with polychoric method handles a constant column without error" , {
173+ skip_if_not_installed(" polycor" )
174+
171175 set.seed(123 )
172176 n <- 100
173177 cut5 <- function (z ) as.integer(cut(z , breaks = c(- Inf , - 0.84 , - 0.25 , 0.25 , 0.84 , Inf )))
@@ -184,6 +188,8 @@ test_that("do_cor with polychoric method handles a constant column without error
184188})
185189
186190test_that(" do_cor with polychoric method handles complex column names" , {
191+ skip_if_not_installed(" polycor" )
192+
187193 set.seed(123 )
188194 n <- 100
189195 cut5 <- function (z ) as.integer(cut(z , breaks = c(- Inf , - 0.84 , - 0.25 , 0.25 , 0.84 , Inf )))
@@ -200,6 +206,8 @@ test_that("do_cor with polychoric method handles complex column names", {
200206})
201207
202208test_that(" do_cor with polychoric method accepts use values hetcor does not support" , {
209+ skip_if_not_installed(" polycor" )
210+
203211 # hetcor only accepts "complete.obs" and "pairwise.complete.obs", but the public
204212 # do_cor API (and the other methods via cor()/cor.test()) also accept "everything",
205213 # "all.obs", and "na.or.complete". Those must be mapped, not passed through as an error.
@@ -218,6 +226,8 @@ test_that("do_cor with polychoric method accepts use values hetcor does not supp
218226})
219227
220228test_that(" do_cor with polychoric method for grouped (repeat-by) data" , {
229+ skip_if_not_installed(" polycor" )
230+
221231 # Repeat By on Analytics View maps to group_by(). Each group must get its own
222232 # polychoric correlation. Group A has a positive relationship, group B a negative one.
223233 set.seed(123 )
@@ -238,6 +248,8 @@ test_that("do_cor with polychoric method for grouped (repeat-by) data", {
238248})
239249
240250test_that(" do_cor with polychoric method handles NA values via pairwise complete obs" , {
251+ skip_if_not_installed(" polycor" )
252+
241253 # Survey data routinely has missing responses (NA). The default use="pairwise.complete.obs"
242254 # must drop NAs pairwise rather than error, so every pair is still estimated.
243255 set.seed(123 )
0 commit comments