MicrobiomeStat icon indicating copy to clipboard operation
MicrobiomeStat copied to clipboard

generate_beta_test_single(): Error in colnames<-(*tmp*, value = colnames(lhs)) : attempt to set 'colnames' on an object with less than two dimensions

Open cami3 opened this issue 2 years ago • 10 comments
trafficstars

Thank you very much for this great package ! I encountered an error while running the tutorial: generate_beta_test_single() returns Error in colnames<-(*tmp*, value = colnames(lhs)) : attempt to set 'colnames' on an object with less than two dimensions

as in the screenshot , do you have any idea what's happening here? Schermata 2023-09-18 alle 17 35 48

cami3 avatar Sep 18 '23 15:09 cami3

Hello @cami3 ,

Thank you for reaching out with your query regarding the generate_beta_test_single function in the MicrobiomeStat package. I took the time to run the exact code you provided on my end, but I didn't encounter any issues.

It's possible that there might be some conflicts or issues specific to your setup or environment. As a troubleshooting step, I recommend trying the following:

  1. Reinstall the MicrobiomeStat package. It's possible that there might have been some issues during your initial installation.
  2. Additionally, consider reinstalling the GUniFrac package, as it might play a role in the function you're working with.

Please ensure that you have the latest versions of all the required dependencies and packages. If after these steps you continue to face the issue, please provide more details about your system setup and any error messages you're receiving, so I can assist you further.

Best regards,

Chen YANG Screenshot 2023-09-19 at 08 52 19

cafferychen777 avatar Sep 19 '23 00:09 cafferychen777

Thank you a lot for taking the time to troubleshoot, apparently there were some issues in the environment, and after closing and restarting the session it all worked as expected. Thanks again for this great package !

cami3 avatar Sep 19 '23 15:09 cami3

Hello @cami3 ,

I'm delighted to hear that the issue has been resolved! Environmental conflicts can sometimes cause unexpected behavior, so I'm glad a session restart did the trick. Thank you for the kind words about the MicrobiomeStat package. It's feedback like yours that keeps us motivated to improve and ensure the best user experience.

If you have any more questions or encounter other issues in the future, please don't hesitate to reach out. We're always here to help.

Warm regards,

Chen YANG

cafferychen777 avatar Sep 20 '23 01:09 cafferychen777

I encountered the same error. Restarting the session, reinstalling MicrobiomeStat and GUniFrac packages but the problem remains.

qqwxp avatar Nov 03 '23 08:11 qqwxp

Dear @qqwxp,

Thank you for bringing this to my attention. In order to better diagnose the issue, could you kindly provide your data in R Data format and share the code you're using? This will allow me to replicate the problem in my own environment, which will greatly expedite the troubleshooting process.

Looking forward to your response.

Best regards, Chen YANG

cafferychen777 avatar Nov 03 '23 12:11 cafferychen777

@cafferychen777 Thank you for your reply. However, this error is very likely unrelated to my data, as I also encounter this error when using the example data (peerj32.obj). image

My environment: Windows 11, 22H2 R version 4.3.1 MicrobiomeStat v1.1.2 GUniFrac v1.8

qqwxp avatar Nov 06 '23 01:11 qqwxp

Dear @qqwxp,

Thank you for reaching out and providing the details about the error you're encountering with the MicrobiomeStat package.

I've tested the package using the same data and environment as you provided. Below is my session information:

> sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: x86_64-apple-darwin20 (64-bit)
Running under: macOS Sonoma 14.0

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Asia/Shanghai
tzcode source: internal

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

other attached packages:
[1] MicrobiomeStat_1.1.2 tibble_3.2.1         rlang_1.1.1         

loaded via a namespace (and not attached):
  [1] remotes_2.4.2.1     inline_0.3.19       testthat_3.2.0      permute_0.9-7       magrittr_2.0.3     
  [6] clue_0.3-65         matrixStats_1.0.0   compiler_4.3.1      mgcv_1.8-42         callr_3.7.3        
 [11] vctrs_0.6.3         rmutil_1.1.10       stringr_1.5.0       profvis_0.3.8       pkgconfig_2.0.3    
 [16] crayon_1.5.2        fastmap_1.1.1       ellipsis_0.3.2      pander_0.6.5        utf8_1.2.3         
 [21] modeest_2.4.0       promises_1.2.1      rmarkdown_2.25      sessioninfo_1.2.2   ps_1.7.5           
 [26] nloptr_2.0.3        tinytex_0.47        purrr_1.0.2         xfun_0.40           cachem_1.0.8       
 [31] later_1.3.1         ggprism_1.0.4       parallel_4.3.1      prettyunits_1.2.0   cluster_2.1.4      
 [36] R6_2.5.1            stringi_1.7.12      RColorBrewer_1.1-3  boot_1.3-28.1       pkgload_1.3.3      
 [41] rpart_4.1.19        brio_1.1.3          numDeriv_2016.8-1.1 Rcpp_1.0.11         iterators_1.0.14   
 [46] knitr_1.44          usethis_2.2.2       httpuv_1.6.11       Matrix_1.5-4.1      splines_4.3.1      
 [51] tidyselect_1.2.0    rstudioapi_0.15.0   yaml_2.3.7          vegan_2.6-4         timeDate_4022.108  
 [56] codetools_0.2-19    miniUI_0.1.1.1      processx_3.8.2      pkgbuild_1.4.2      lattice_0.21-8     
 [61] lmerTest_3.1-3      withr_2.5.1         shiny_1.7.5         evaluate_0.22       stable_1.1.6       
 [66] desc_1.4.2          urlchecker_1.0.1    pillar_1.9.0        renv_1.0.3          foreach_1.5.2      
 [71] generics_0.1.3      rprojroot_2.0.3     ggplot2_3.4.4       munsell_0.5.0       scales_1.2.1       
 [76] minqa_1.2.6         timeSeries_4031.107 xtable_1.8-4        glue_1.6.2          statip_0.2.3       
 [81] pheatmap_1.0.12     tools_4.3.1         lme4_1.1-34         spatial_7.3-16      fBasics_4031.95    
 [86] fs_1.6.3            grid_4.3.1          tidyr_1.3.0         ape_5.7-1           devtools_2.4.5     
 [91] colorspace_2.1-0    nlme_3.1-162        cli_3.6.1           fansi_1.0.4         dplyr_1.1.3        
 [96] gtable_0.3.4        ggh4x_0.2.6         stabledist_0.7-1    digest_0.6.33       ggrepel_0.9.4      
[101] htmlwidgets_1.6.2   memoise_2.0.1       htmltools_0.5.6.1   lifecycle_1.0.3     statmod_1.5.0      
[106] mime_0.12           GUniFrac_1.8        MASS_7.3-60   

From my end, I did not encounter any issues. Screenshot 2023-11-06 at 14 01 55

Here are a few steps we can take to troubleshoot:

  1. Reinstallation: It's possible that something went wrong during the package installation. Please try reinstalling the MicrobiomeStat package and its dependencies.
  2. Package Conflicts: Occasionally, other loaded R packages might cause conflicts. Consider starting a fresh R session without any additional libraries loaded and only load MicrobiomeStat to see if the error persists.
  3. Windows Specific Issue: Since I'm testing on macOS and you're on Windows, there might be OS-specific issues. We'll need to further investigate this if the above steps don't resolve the issue.

Could you also provide more information about the exact error message you're seeing, especially the content of the image you've linked? That would help in diagnosing the issue more precisely.

Thank you for your patience, and I'll do my best to assist you.

Best regards, Chen YANG

cafferychen777 avatar Nov 06 '23 06:11 cafferychen777

I found this to be a very strange error: I used your sample data and it worked fine the first time, but when I ran it again, an error occurred.

# Load the dataset
data(peerj32.obj)
data.obj = peerj32.obj

# Specify variable names
group.var = "group" # Variable used for grouping samples
vis.adj.vars = c("sex") # Covariates to visualize in plots
test.adj.vars = c("sex") # Covariates to be adjusted for in statistical tests
subject.var = "subject" # Variable used for subject identification
time.var = "time" # Variable used for time points

# Specify diversity indices
alpha.name = c("shannon", "observed_species") # Alpha diversity indices to calculate
dist.name = c("BC",'Jaccard') # Beta diversity indices to calculate

# Specify feature levels for visualization and testing
vis.feature.level = c("Phylum", "Family", "Genus") # Feature levels to use for visualization
test.feature.level = "Family" # Feature level to use for testing

# Specify other parameters
feature.dat.type = "count" # Type of the feature data
theme.choice = "bw" # Theme choice for the plots
base.size = 20 # Base size for the plots
feature.mt.method = "none" # Multiple testing method for features
feature.sig.level = 0.2 # Significance level cutoff for highlighting features

# Specify output file
output.file = "./mStat_generate_report_single_example.pdf" # Replace with your own file path for the output report

# Specify optional parameters
dist.obj = NULL # Replace with a pre-computed distance matrix if available
alpha.obj = NULL # Replace with a pre-computed alpha diversity matrix if available
depth = NULL # Replace with a desired depth for rarefying samples
t.level = "1" # Replace with a desired time level if time points have multiple levels
feature.box.axis.transform = "sqrt" # Axis transformation for feature boxplots
strata.var = "sex" # Variable to stratify by in diversity calculations and statistical tests

# Specify parameters for feature retention
bar.area.feature.no = 20 # Number of top abundant features to retain in barplot and areaplot
heatmap.feature.no = 20 # Number of top abundant features to retain in heatmap
dotplot.feature.no = 40 # Number of top abundant features to retain in dotplot

# Run the function
mStat_generate_report_single(
   data.obj = data.obj,
   dist.obj = dist.obj,
   alpha.obj = alpha.obj,
   group.var = group.var,
   vis.adj.vars = vis.adj.vars,
   test.adj.vars = test.adj.vars,
   subject.var = subject.var,
   time.var = time.var,
   alpha.name = alpha.name,
   depth = depth,
   dist.name = dist.name,
   t.level = t.level,
   feature.box.axis.transform = feature.box.axis.transform,
   strata.var = strata.var,
   vis.feature.level = vis.feature.level,
   test.feature.level = test.feature.level,
   feature.dat.type = feature.dat.type,
   bar.area.feature.no = bar.area.feature.no,
   heatmap.feature.no = heatmap.feature.no,
   dotplot.feature.no = dotplot.feature.no,
   feature.mt.method = feature.mt.method,
   feature.sig.level = feature.sig.level,
   theme.choice = theme.choice,
   base.size = base.size,
   output.file = output.file
 )

First try: image

Second try: image

qqwxp avatar Nov 13 '23 09:11 qqwxp

Dear @qqwxp,

Thank you for reaching out with your concern. The error you are experiencing may be due to the PermanovaG function accessing global variables in your R environment. Global variables can be influenced by various factors in your R session, leading to inconsistent behavior across different runs.

To address this, I recommend clearing your environment variables before rerunning the script. You can do this in RStudio by clicking on the "Clear" button located in the top-right corner of the Environment pane. This action will remove all objects from the current environment, ensuring a clean workspace.

After clearing the environment, please try rerunning your script to see if the issue persists. This should help in achieving consistent results across different runs.

Please let me know if this resolves your issue or if you need further assistance.

Best regards,

Chen YANG

cafferychen777 avatar Nov 13 '23 10:11 cafferychen777

@cafferychen777 Thanks. But it doesn't work

qqwxp avatar Nov 14 '23 06:11 qqwxp