daniel1noble / orchaRd

Extending the Orchard Plot for Meta-analysis
https://daniel1noble.github.io/orchaRd/
11 stars 6 forks source link

Error in data.frame(yi, vi, moderator, stdy, type) #53

Closed ecologyxy closed 11 months ago

ecologyxy commented 11 months ago

Hi, I just newly use orchaRd package, when I try the code in Example 1, I got an error:

 > data(eklof)
 > eklof<-metafor::escalc(measure="ROM", n1i=N_control, sd1i=SD_control,
 +                        m1i=mean_control, n2i=N_treatment, sd2i=SD_treatment, m2i=mean_treatment,
 +                        data=eklof)
 > # Add the unit level predictor
 > eklof$Datapoint<-as.factor(seq(1, dim(eklof)[1], 1))
 > # fit a MLMR - accounting for some non-independence
 > eklof_MR<-metafor::rma.mv(yi=yi, V=vi, mods=~ Grazer.type-1,
 +                           random=list(~1|ExptID, ~1|Datapoint), data=eklof)
 > results <- mod_results(eklof_MR, mod = "Grazer.type", group = "ExptID")

and error message: Error in data.frame(yi, vi, moderator, stdy, type) : arguments imply differing number of rows: 34, 0, 1 Was there some detail I overlooked that's caused this error? How can I fix it ? The orchaRd package was Version 2.0. Thanks very much.

daniel1noble commented 11 months ago

Hi @ecologyxy. I'm not getting this error. Can you provide more details? What version of R? OrchaRd etc? SessionInfo() would be useful. Have you tried a fresh install?

ecologyxy commented 11 months ago

Hi, I try to reinstalled the orchaRd package, use:

devtools::install_github("daniel1noble/orchaRd", force = TRUE)

and try the sessioninfo function, use:

> library(sessioninfo)
> sessioninfo::session_info()
─ Session info ────────────────────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.3.1 (2023-06-16 ucrt)
 os       Windows 10 x64 (build 19045)
 system   x86_64, mingw32
 ui       RStudio
 language (EN)
 collate  Chinese (Simplified)_China.utf8
 ctype    Chinese (Simplified)_China.utf8
 tz       Asia/Shanghai
 date     2023-10-24
 rstudio  2023.06.1+524 Mountain Hydrangea (desktop)
 pandoc   NA

─ Packages ────────────────────────────────────────────────────────────────────────────────────────
 package     * version date (UTC) lib source
 cli           3.4.1   2022-09-23 [1] CRAN (R 4.2.2)
 rlang         1.1.1   2023-04-28 [1] CRAN (R 4.3.0)
 rstudioapi    0.15.0  2023-07-07 [1] CRAN (R 4.3.1)
 sessioninfo * 1.2.2   2021-12-06 [1] CRAN (R 4.3.1)

 [1] D:/Program Files/R/R-4.3.1/library

───────────────────────────────────────────────────────────────────────────────────────────────────

Then I retried the code in Example 1 of ?orchard_plot, as:

> library(orchaRd)

Loading the 'orchaRd' package (version 2.0). For an
introduction and vignette to the package please see: https://daniel1noble.github.io/orchaRd/

Attaching package: ‘orchaRd’

The following object is masked _by_ ‘.GlobalEnv’:

    english

> library(metafor)
Loading required package: Matrix
Loading 'metafor' package (version 2.4-0). For an overview 
and introduction to the package please type: help(metafor).
> data(eklof)
> eklof<-metafor::escalc(measure="ROM", n1i=N_control, sd1i=SD_control,
+                        m1i=mean_control, n2i=N_treatment, sd2i=SD_treatment, m2i=mean_treatment,
+                        data=eklof)
> # Add the unit level predictor
> eklof$Datapoint<-as.factor(seq(1, dim(eklof)[1], 1))
> # fit a MLMR - accounting for some non-independence
> eklof_MR<-metafor::rma.mv(yi=yi, V=vi, mods=~ Grazer.type-1,
+                           random=list(~1|ExptID, ~1|Datapoint), data=eklof)
> results <- mod_results(eklof_MR, mod = "Grazer.type", group = "ExptID")

Then still got the error:

Error in data.frame(yi, vi, moderator, stdy, type) : 
  arguments imply differing number of rows: 34, 0, 1

It looks like some bug in the setting of R caused this problem?

ecologyxy commented 11 months ago

Some additional information. After I load these packages, I use sessioninfo:

> sessioninfo::session_info()
─ Session info ────────────────────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.3.1 (2023-06-16 ucrt)
 os       Windows 10 x64 (build 19045)
 system   x86_64, mingw32
 ui       RStudio
 language (EN)
 collate  Chinese (Simplified)_China.utf8
 ctype    Chinese (Simplified)_China.utf8
 tz       Asia/Shanghai
 date     2023-10-24
 rstudio  2023.06.1+524 Mountain Hydrangea (desktop)
 pandoc   NA

─ Packages ────────────────────────────────────────────────────────────────────────────────────────
 ! package     * version date (UTC) lib source
   cli           3.4.1   2022-09-23 [1] CRAN (R 4.2.2)
   lattice       0.21-8  2023-04-05 [1] CRAN (R 4.3.1)
   magrittr      2.0.1   2020-11-17 [1] CRAN (R 4.1.1)
   Matrix      * 1.5-4.1 2023-05-18 [1] CRAN (R 4.3.1)
   metafor     * 2.4-0   2020-03-19 [1] CRAN (R 4.0.3)
 D nlme          3.1-162 2023-01-31 [1] CRAN (R 4.3.1)
   orchaRd     * 2.0     2023-10-14 [1] Github (daniel1noble/orchaRd@9f359b8)
   rlang         1.1.1   2023-04-28 [1] CRAN (R 4.3.0)
   rstudioapi    0.15.0  2023-07-07 [1] CRAN (R 4.3.1)
   sessioninfo * 1.2.2   2021-12-06 [1] CRAN (R 4.3.1)

 [1] D:/Program Files/R/R-4.3.1/library

 D ── DLL MD5 mismatch, broken installation.

Does " D ── DLL MD5 mismatch, broken installation." means something important?

daniel1noble commented 11 months ago

Thanks for the details. To be honest, I'm not too sure what might be happening here. We have R CMD checks on windows that are passing just fine, vignettes rendering fine and all unit tests are working. It would seem like this might have something to do with installation issues of packages that are dependencies. Given that library(orchaRd) is loading suggests that it is not a problem with orchaRd loading on your machine. Can you run other examples in the vignette? Do they also fail for you?

ecologyxy commented 11 months ago

Thanks for reply, I tried the code of Example 2 in ?orchard_plot, and still got an error:

> library(orchaRd)
> library(metafor)
Loading required package: Matrix

Attaching package: ‘Matrix’

The following objects are masked from ‘package:tidyr’:

    expand, pack, unpack

Loading 'metafor' package (version 2.4-0). For an overview 
and introduction to the package please type: help(metafor).
> data(lim)
> lim$vi<- 1/(lim$N - 3)
> lim_MR<-metafor::rma.mv(yi=yi, V=vi, mods=~Phylum-1, random=list(~1|Article,
+                                                                  ~1|Datapoint), data=lim)
> orchard_plot(lim_MR, mod = "Phylum", group = "Article",
+              xlab = "Correlation coefficient", transfm = "tanh", N = lim$N)
Error in data.frame(yi, vi, moderator, stdy, type) : 
  arguments imply differing number of rows: 357, 0, 1

It's confusing me.

daniel1noble commented 11 months ago

Yes, it is confusing. I can't really reproduce these issues so I'm not entirely sure what might be going on. Sorry. Could you try a fresh installation of R and/or RStudio and reload just the dependencies for orchaRd? Maybe this will work?

ecologyxy commented 11 months ago

Hi, after I reinstalled R and packages, everything functioned as it should. Still not sure what caused the errors, but it works now. Thanks very much!

daniel1noble commented 11 months ago

Great to hear! The mysteries of installation. I'm glad you got it all sorted.