strengejacke / esc

Effect Size Computation for Meta Analysis
https://strengejacke.github.io/esc
20 stars 6 forks source link

Calling && or || with either argument of length greater than one #12

Closed pgonzaleze closed 11 months ago

pgonzaleze commented 1 year ago

I recently reviewed an old script but now I got this error when I run it on a new computer with R version 4.3.1:

Error in missing(grp1sd) || is.null(grp1sd) || is.na(grp1sd) : 'length = 59' in coercion to 'logical(1)'

I wonder if the error is related to this what is said here https://github.com/kaz-yos/tableone/issues/93: "Message from the CRAN maintainer:

NEWS for R-devel has

• Calling && or || with either argument of length greater than one now gives a warning (which it is intended will become an error)."

strengejacke commented 1 year ago

Do you have a reproducible example?

pgonzaleze commented 1 year ago

Sure thing, here it is:

library(esc)

Create vectors for the data

Year <- c(2015, 2015, 2015) Author <- c("Anttila et al. 2015", "Anttila et al. 2015", "Anttila et al. 2015") Organism <- c("Atlantic salmon (Salmo salar)", "Arctic char (Salvelinus alpinus)", "Atlantic salmon (Salmo salar)") µ1 <- c(29.75, 28, 27.3) µ2 <- c(29.35, 27.82, 29.34) SD1 <- c(0.193649167, 0.309838668, 0.232379001) SD2 <- c(0.232379001, 0.271108834, 0.271108834) Replicates <- c(5, 3, 6) SampleSizeCtrl <- c(15, 15, 15) SampleSize <- c(15, 15, 15)

Create the data frame

int_db <- data.frame( Year = Year, Author = Author, Organism = Organism, µ1 = µ1, µ2 = µ2, SD1 = SD1, SD2 = SD2, Replicates = Replicates, SampleSizeCtrl = SampleSizeCtrl, SampleSize = SampleSize )

save lists of medias, SD and sample sizes, use "unlist" to convert a list to vector

media1 <- as.numeric(unlist(int_db[,4]))
media2 <- as.numeric(unlist(int_db[,5])) sd1 <- as.numeric(unlist(int_db[,6])) sd2 <- as.numeric(unlist(int_db[,7])) replicates <- as.numeric(unlist(int_db[,8])) replicates <- na_replace(replicates, 1) # change NA?s to 1 if any sample_ctrl <- as.numeric(unlist(int_db[,9])) # replicates sample_n <- as.numeric(unlist(int_db[,10])) # replicates

compute the Hedges g

g=(esc_mean_sd(grp1m=media1,grp1sd=sd1,grp1n=sample_n, grp2m=media2,grp2sd=sd2,grp2n=sample_n, es.type = 'g'))

pgonzaleze commented 1 year ago

I forgot to attach the output; after running the sample code I get this error:

Error in missing(grp1sd) || is.null(grp1sd) || is.na(grp1sd) : 'length = 3' in coercion to 'logical(1)'

The same code run perfectly last year (using R version 3.6.1), but now I get this error (using 4.3.1)

gl-007 commented 1 year ago

My team ran into the same problem when upgrading to R 4.3.1. The issue seems to be the checks is.na() in lines 54, 55 and 56 in the function. I did a quick hot fix via any(is.na()) which avoids that error, but not sure if that is the desired behaviour.

pgonzaleze commented 1 year ago

Thanks @gl-007, I tried it and I got this error, do you happen to know how to solve this?: In addition: Warning message: Either totalsd or both grp1sd and grp2sd must be specified.

UPDATE: Since I do not have NA's, I removed lines 53 to 58 (in the fuction) and it worked!