liger icon indicating copy to clipboard operation
liger copied to clipboard

Problem with package name change: load older liger object

Open samuel-marsh opened this issue 4 years ago • 5 comments

Hi Liger Team,

Running into issue trying to load an object that was created with package when it was named liger and loading it into workspace where package is now rliger (as installed from CRAN). Do you have workaround or solution that you can implement within package?

Thanks! Sam

obj <- qread("obj_name.qs")

Loading required package: liger
Error in .requirePackage(package) : 
  unable to find required package ‘liger’
In addition: Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
  there is no package called ‘liger’
10 Aug 2021 13:16:57 [rsession-rstudio] ERROR r error 4 (R code execution error) [errormsg: Error in .requirePackage(package) : 
  unable to find required package ‘liger’
]; OCCURRED AT rstudio::core::Error rstudio::r::exec::{anonymous}::evaluateExpressionsUnsafe(SEXP, SEXP, SEXPREC**, rstudio::r::sexp::Protect*, rstudio::r::exec::{anonymous}::EvalType) src/cpp/r/RExec.cpp:186; LOGGED FROM: rstudio::core::json::Value rstudio::session::modules::environment::varToJson(SEXP, const Variable&) src/cpp/session/modules/environment/EnvironmentUtils.cpp:223
sessionInfo

> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.2 LTS

Matrix products: default
BLAS/LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.8.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8   
 [6] LC_MESSAGES=C              LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
 [1] viridis_0.6.1          viridisLite_0.4.0      scCustomize_0.5.0.9008 SeuratWrappers_0.3.0   SeuratObject_4.0.2     Seurat_4.0.3          
 [7] rliger_1.0.0           patchwork_1.1.1        Matrix_1.3-4           cowplot_1.1.1          qs_0.25.1              forcats_0.5.1         
[13] stringr_1.4.0          dplyr_1.0.7            purrr_0.3.4            readr_1.4.0            tidyr_1.1.3            tibble_3.1.2          
[19] ggplot2_3.3.5          tidyverse_1.3.1       

loaded via a namespace (and not attached):
  [1] readxl_1.3.1            backports_1.2.1         plyr_1.8.6              igraph_1.2.6            lazyeval_0.2.2          splines_4.1.0          
  [7] RApiSerialize_0.1.0     listenv_0.8.0           scattermore_0.7         digest_0.6.27           foreach_1.5.1           htmltools_0.5.1.1      
 [13] fansi_0.5.0             magrittr_2.0.1          tensor_1.5              cluster_2.1.2           doParallel_1.0.16       ROCR_1.0-11            
 [19] remotes_2.4.0           globals_0.14.0          modelr_0.1.8            RcppParallel_5.1.4      matrixStats_0.59.0      R.utils_2.10.1         
 [25] spatstat.sparse_2.0-0   colorspace_2.0-2        rvest_1.0.0             ggrepel_0.9.1           haven_2.4.1             crayon_1.4.1           
 [31] jsonlite_1.7.2          spatstat.data_2.1-0     stringfish_0.15.1       survival_3.2-11         zoo_1.8-9               iterators_1.0.13       
 [37] glue_1.4.2              polyclip_1.10-0         gtable_0.3.0            leiden_0.3.8            future.apply_1.7.0      abind_1.4-5            
 [43] scales_1.1.1            DBI_1.1.1               pbmc3k.SeuratData_3.1.4 miniUI_0.1.1.1          Rcpp_1.0.7              xtable_1.8-4           
 [49] riverplot_0.10          reticulate_1.20         spatstat.core_2.2-0     rsvd_1.0.5              bit_4.0.4               mclust_5.4.7           
 [55] htmlwidgets_1.5.3       httr_1.4.2              FNN_1.1.3               RColorBrewer_1.1-2      ellipsis_0.3.2          ica_1.0-2              
 [61] farver_2.1.0            pkgconfig_2.0.3         R.methodsS3_1.8.1       uwot_0.1.10             dbplyr_2.1.1            deldir_0.2-10          
 [67] janitor_2.1.0           utf8_1.2.1              labeling_0.4.2          tidyselect_1.1.1        rlang_0.4.11            reshape2_1.4.4         
 [73] later_1.2.0             munsell_0.5.0           cellranger_1.1.0        tools_4.1.0             cli_2.5.0               generics_0.1.0         
 [79] broom_0.7.8             ggridges_0.5.3          fastmap_1.1.0           goftest_1.2-2           bit64_4.0.5             fs_1.5.0               
 [85] fitdistrplus_1.1-5      RANN_2.6.1              pbapply_1.4-3           future_1.21.0           nlme_3.1-152            mime_0.11              
 [91] R.oo_1.24.0             xml2_1.3.2              hdf5r_1.3.3             compiler_4.1.0          rstudioapi_0.13         plotly_4.9.4.1         
 [97] png_0.1-7               spatstat.utils_2.2-0    reprex_2.0.0            stringi_1.6.2           lattice_0.20-44         vctrs_0.3.8            
[103] pillar_1.6.1            lifecycle_1.0.0         BiocManager_1.30.15     spatstat.geom_2.2-0     lmtest_0.9-38           RcppAnnoy_0.0.18       
[109] data.table_1.14.0       irlba_2.3.3             httpuv_1.6.1            R6_2.5.0                promises_1.2.0.1        KernSmooth_2.23-20     
[115] gridExtra_2.3           parallelly_1.26.0       codetools_0.2-18        MASS_7.3-54             assertthat_0.2.1        withr_2.4.2            
[121] sctransform_0.3.2       mgcv_1.8-36             parallel_4.1.0          hms_1.1.0               grid_4.1.0              rpart_4.1-15           
[127] snakecase_0.11.0        Rtsne_0.15              shiny_1.6.0             lubridate_1.7.10

samuel-marsh avatar Aug 10 '21 13:08 samuel-marsh

I'm curious what a nice way to do this is. One quick hacky solution I did when I hit the same problem was to find where R was storing the package directories and then changing the DESCRIPTION file so instead of saying Package: rliger it says Package: liger

Good thing I don't need the other imposter liger package :) !

JZL avatar Aug 10 '21 13:08 JZL

Ya not sure either. If you do happen to have the other "liger" package installed then the objects will load and you can interact with them properly using rliger. But obviously that's also not really good solution.

samuel-marsh avatar Aug 10 '21 14:08 samuel-marsh

One thing which I have found generally helpful is running R/rstudio from within a conda environment because R packages are so brittle. It also allows me to experiment with this without ruining the rest of my environment. So to be completely honest, what I did in this situation was make a copy of my anaconda R environment and messed around for a while to get liger to load. Then once I got the information I needed I went back to my main R environment. But there was at least one time where even with this I had trouble loading it. I think at that point I still managed to pull out the like @H matrix/clusters which I needed, even though R was still complaining

I can help with this conda thing. I should write up how I do the conda thing anyway

We do upload a good number of liger RDS files into public repositories so it can be frustrating how brittle it is, but I don't know a better way

JZL avatar Aug 10 '21 14:08 JZL

Ya I've done similar thing within R using packrat/renv packages. I mean one other solution is that user can download the old release from github directly where package is named liger to open the object but again not really simple. Other issue is that as of now there isn't way to further modify that object so that it could be saved and shared with others without having to do things again in same way to open...

samuel-marsh avatar Aug 11 '21 16:08 samuel-marsh

Hi Sam and Jonah,

Sorry for the inconvenience brought by renaming the package and thanks for bringing it to discussion. As of right now, it seems there is no other elegant approach to load the liger::liger object without the "liger" package being installed. However, once the old liger object is loaded, you could update it via function shown below:

updateLigerObject <- function(liger_object_old){
  liger_object_new = rliger::createLiger([email protected])
  [email protected] = [email protected]
  [email protected] = [email protected]
  [email protected] = [email protected]
  [email protected] = [email protected]
  [email protected] = [email protected]
  [email protected] = [email protected]
  liger_object_new@H = liger_object_old@H
  [email protected] = [email protected]
  liger_object_new@W = liger_object_old@W
  liger_object_new@V = liger_object_old@V
  liger_object_new@A = liger_object_old@A
  liger_object_new@B = liger_object_old@B
  [email protected] = [email protected]
  [email protected] = [email protected]
  liger_object_new@clusters = liger_object_old@clusters
  [email protected] = [email protected]
  liger_object_new@parameters = liger_object_old@parameters
  liger_object_new@snf = liger_object_old@snf
  liger_object_new@version = liger_object_old@version
  return(liger_object_new)
}

test_new = updateLigerObject(test_old)

In this way, the new object (test_new) could be modified, saved and shared as an rliger::liger object. There should be no further issue for others to load it.

Hope this helps.

Best, Chao

cgao90 avatar Aug 11 '21 18:08 cgao90