cafferychen777 / MicrobiomeStat

Track, Analyze, Visualize: Unravel Your Microbiome's Temporal Pattern with MicrobiomeStat
https://www.microbiomestat.wiki/
31 stars 4 forks source link

time.var = NULL, in mStat_generate_report_single () causes an error and stops rendering #23

Open RachBioHaz opened 9 months ago

RachBioHaz commented 9 months ago

Hi, I'm running into an issue with the mStat_generate_report_single() when I am using data without a time variable. Hoping you can help. Cheers Rachele

Describe the Bug

Trying to run the report without a time variable, but the report fails. If the time.var field = NULL in mStat_generate_report_single() , an error appears and the report stops rendering.

The error may be related to issue #15 - seems similar

Reproducible Example Using the data set code below generates the error

data(ecam.obj)

mStat_generate_report_single(
  data.obj = ecam.obj,
  dist.obj = NULL,
  alpha.obj = NULL,
  group.var = "delivery",
  vis.adj.vars = "diet",
  test.adj.vars = "diet",
  subject.var = "subject.id",
  time.var = NULL,
  alpha.name = c("shannon", "observed_species"),
  depth = NULL,
  dist.name = c("BC",'Jaccard'),
  t.level = NULL,
  feature.box.axis.transform = "sqrt",
  strata.var = "antiexposedall",
  vis.feature.level = c("Phylum", "Family", "Genus"),
  test.feature.level = "Family",
  feature.dat.type = "proportion",
  theme.choice = "bw",
  base.size = 20,
  feature.mt.method = "none",
  feature.sig.level = 0.2,
  output.file = "C:/Scratch/Testecam.obj_report.pdf"
)

Expected Behavior I expected the report to run either with NULL in the field or with it removed. The documentation does not make it clear what the options are.

Actual Behavior

The function will not run if it is removed ("argument "time.var" is missing, with no default"), and fails if NULL is used with the error message below:

processing file: file57fc6c274895.Rmd |.... | 4% [input-parameters-summary]
Quitting from lines 18-105 [input-parameters-summary] (file57fc6c274895.Rmd) Error in data.frame(): ! arguments imply differing number of rows: 34, 33 Backtrace:

  1. base::data.frame(...)

Screenshots Traceback: image

Environment Information:

sessionInfo() R version 4.3.2 (2023-10-31 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 11 x64 (build 22621)

Matrix products: default

locale: [1] LC_COLLATE=English_Australia.utf8 LC_CTYPE=English_Australia.utf8 LC_MONETARY=English_Australia.utf8 LC_NUMERIC=C
[5] LC_TIME=English_Australia.utf8

time zone: Australia/Sydney tzcode source: internal

attached base packages: [1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached): [1] digest_0.6.33 styler_1.10.2 fastmap_1.1.1 xfun_0.41 magrittr_2.0.3 glue_1.6.2 R.utils_2.12.3
[8] knitr_1.45 htmltools_0.5.7 lifecycle_1.0.4 cli_3.6.1 R.methodsS3_1.8.2 vctrs_0.6.5 reprex_2.0.2
[15] data.table_1.14.10 withr_2.5.2 compiler_4.3.2 R.oo_1.25.0 R.cache_0.16.0 purrr_1.0.2 rstudioapi_0.15.0 [22] tools_4.3.2 clipr_0.8.0 rlang_1.1.2 fs_1.6.3 htmlwidgets_1.6.4

Additional Context Add any other context about the problem here, e.g., is this issue sporadic or consistent? Did it work in previous versions?

cafferychen777 commented 9 months ago

Dear Rachele,

I'm pleased to inform you that the issue you encountered with mStat_generate_report_single() when using data without a time variable has been successfully resolved. The solution involved modifying the function's handling of the time.var parameter.

The recent updates in the Git repository include changes where the time.var argument is now set to default to NULL. This adjustment ensures that the function can handle scenarios where a time variable is not present in the dataset. The relevant snippet from the Git log is as follows:

mStat_generate_report_single <- function(data.obj,
                                         ...
                                         subject.var,
                                         time.var = NULL,
                                         ...
                                         alpha.name = c("shannon", "observed_species"),
                                         ...
                                         )

Additionally, I implemented a condition to check the status of time.var, ensuring that it behaves correctly when it is set to NULL:

custom_time.var_status <- ifelse(is.null(time.var), 'NULL', time.var)

These changes should address the error you were experiencing, as the function now gracefully handles the absence of a time variable.

I greatly appreciate your bringing this matter to my attention. Your feedback is invaluable in improving the package. Please wait for the updated package to be available on GitHub, after which this issue should be resolved in your environment.

Thank you for your patience and support.

Best regards,

Chen YANG

Screenshot 2023-12-12 at 23 44 59
RachBioHaz commented 9 months ago

Thank you for such a prompt response. Cheers