MomX / Momocs

:dove: Morphometrics using R
http://momx.github.io/Momocs/
51 stars 19 forks source link

Combining multiple Out objects from RData files #210

Open mishaploid opened 4 years ago

mishaploid commented 4 years ago

Hello!

To landmark a large group of images, we have split them into manageable chunks and saved the output as RData objects. I am attempting to read in and combine the RData objects, but reach an error when I try to apply coo functions to the output.

I am able to read in and combine the individual files into a single Out object using:

files <- list.files("data/processed",
                    full.names = TRUE)

spam <- map(files, function(x) {
  load(x)
  get(ls()[ls() != "filename"])
})

eggs <- Momocs::combine(spam[1:length(spam)])

Then I attempt to check the output using:

eggs %>%  
  coo_align() %>%
  coo_center() %>%
  coo_scale() %>%
  coo_slide(ldk = 3) %>%
  pile() 

Which results in this error:

Error in sample(x = length(coo), size = subset, replace = FALSE) : 
  object 'coo' not found

I thought maybe one of the files was corrupted, but if I slice the Out object into a group of 1000 or less, the same command consistently works fine and does not return an error (regardless of the number range), e.g.:

eggs %>%  
  slice(1:1000) %>% 
  coo_align() %>%
  coo_center() %>%
  coo_scale() %>%
  coo_slide(ldk = 3) %>%
  pile() 

Any thoughts on what can be causing this behavior? Or options to effectively combine the landmarked data?

Thank you!

Sarah

> sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.5

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

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

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

other attached packages:
 [1] Momocs_1.2.9    forcats_0.4.0   stringr_1.4.0   dplyr_0.8.3     purrr_0.3.3     readr_1.3.1    
 [7] tidyr_1.0.0     tibble_2.1.3    ggplot2_3.2.1   tidyverse_1.3.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.3        lubridate_1.7.4   lattice_0.20-38   prettyunits_1.0.2 ps_1.3.0          assertthat_0.2.1 
 [7] zeallot_0.1.0     rprojroot_1.3-2   digest_0.6.23     R6_2.4.1          cellranger_1.1.0  backports_1.1.5  
[13] reprex_0.3.0      httr_1.4.1        pillar_1.4.3      rlang_0.4.2       curl_4.3          lazyeval_0.2.2   
[19] readxl_1.3.1      rstudioapi_0.10   callr_3.4.0       desc_1.2.0        devtools_2.2.1    munsell_0.5.0    
[25] broom_0.5.3       compiler_3.6.0    modelr_0.1.5      pkgconfig_2.0.3   pkgbuild_1.0.6    tidyselect_0.2.5 
[31] fansi_0.4.0       crayon_1.3.4      dbplyr_1.4.2      withr_2.1.2       grid_3.6.0        nlme_3.1-143     
[37] jsonlite_1.6      gtable_0.3.0      lifecycle_0.1.0   DBI_1.1.0         magrittr_1.5      scales_1.1.0     
[43] cli_2.0.0         stringi_1.4.3     fs_1.3.1          remotes_2.1.0     testthat_2.3.1    xml2_1.2.2       
[49] ellipsis_0.3.0    generics_0.0.2    vctrs_0.2.1       tools_3.6.0       glue_1.3.1        hms_0.5.2        
[55] processx_3.4.1    pkgload_1.0.2     colorspace_1.4-1  sessioninfo_1.1.1 rvest_0.3.5       memoise_1.1.0    
[61] haven_2.2.0       usethis_1.5.1
vbonhomme commented 4 years ago

Hi Sarah, possibly a problem in how Coo are combined. This is natively solved in Momocs2, almost finished now. For now and Momocs, having a couple of what you have in "data/processed" would help.

mishaploid commented 4 years ago

That's great news! Really looking forward to the updates, Momocs has been a great tool for our work. Attaching some examples here - please let me know if you need any additional detail. Thanks for your help!

Momocs_combine_examples.zip

mishaploid commented 4 years ago

Hi Vincent,

I just wanted to follow up on a potential solution for combining multiple Out objects. Are Out objects created in Momocs compatible with Momocs2? If yes, is there an equivalent function to Momocs::combine that we could try?

Thanks!

vbonhomme commented 4 years ago

Momocs2 is not ready yet and many things will change. That being said, Momocs2 wont need combine since all objects are tibbles, they can simply be dplyr::bind_rows(). If you want to import to Out then variations around Out(x$coo, fac=select(x, -coo)) will work. If you want to do the other way round, bind_cols(tibble(coo=x$coo), x$fac) will do the job. These converters are part of Momit, not ready either.

hope this helps,

v

Le lun. 18 mai 2020 à 21:09, Sarah Turner-Hissong notifications@github.com a écrit :

Hi Vincent,

I just wanted to follow up on a potential solution for combining multiple Out objects. Are Out objects created in Momocs compatible with Momocs2? If yes, is there an equivalent function to Momocs::combine that we could try?

Thanks!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/MomX/Momocs/issues/210#issuecomment-630381362, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABECQFX4WRRZUDT4IBJU4RDRSGBWFANCNFSM4MS5FUUQ .

-- vincentbonhomme.fr http://www.vincentbonhomme.fr