In massdataset package, the merge_mass_dataset is more powerful to merge tow mass_dataset class objects.

Data preparation

library(massdataset)
library(tidyverse)

data("expression_data")
data("sample_info")
data("variable_info")

object =
  create_mass_dataset(
    expression_data = expression_data,
    sample_info = sample_info,
    variable_info = variable_info
  )
object1 = object[1:10, 1:5]
object2 = object[5:15, 3:7]
colnames(object1)
#> [1] "Blank_3" "Blank_4" "QC_1"    "QC_2"    "PS4P1"
colnames(object2)
#> [1] "QC_1"  "QC_2"  "PS4P1" "PS4P2" "PS4P3"
rownames(object1)
#>  [1] "M136T55_2_POS" "M79T35_POS"    "M307T548_POS"  "M183T224_POS" 
#>  [5] "M349T47_POS"   "M182T828_POS"  "M299T359_POS"  "M348T844_POS" 
#>  [9] "M344T471_POS"  "M181T436_POS"
rownames(object2)
#>  [1] "M349T47_POS"  "M182T828_POS" "M299T359_POS" "M348T844_POS" "M344T471_POS"
#>  [6] "M181T436_POS" "M345T195_POS" "M304T825_POS" "M137T196_POS" "M359T638_POS"
#> [11] "M270T507_POS"

Merge two mass_dataset

object = 
  merge_mass_dataset(x = object1, y = object2, 
                     sample_direction = "left", 
                     variable_direction = "left", 
                     sample_by = "sample_id", 
                     variable_by = "variable_id")

extract_expression_data(object1)
#>                 Blank_3   Blank_4      QC_1      QC_2     PS4P1
#> M136T55_2_POS        NA        NA 1857924.8 1037763.8 1494436.1
#> M79T35_POS           NA        NA 2821550.2 1304875.3 2471336.1
#> M307T548_POS         NA        NA  410387.6  273687.8  288590.2
#> M183T224_POS         NA        NA        NA        NA        NA
#> M349T47_POS          NA        NA 8730104.8 4105598.5 5141073.2
#> M182T828_POS  3761892.6 2572593.4        NA 3662819.1 5700534.8
#> M299T359_POS         NA        NA 3688690.6 2892719.6 1401632.7
#> M348T844_POS         NA        NA        NA 3131157.7        NA
#> M344T471_POS         NA        NA  589957.0  408610.8        NA
#> M181T436_POS   249352.6  131374.5  248764.1  208789.4  423991.8
extract_expression_data(object2)
#>                   QC_1       QC_2     PS4P1     PS4P2     PS4P3
#> M349T47_POS  8730104.8  4105598.5 5141073.2 8424315.6 7896633.3
#> M182T828_POS        NA  3662819.1 5700534.8 4600172.4 5557014.6
#> M299T359_POS 3688690.6  2892719.6 1401632.7 4055989.5 1577496.3
#> M348T844_POS        NA  3131157.7        NA        NA 3643606.4
#> M344T471_POS  589957.0   408610.8        NA  276913.4  304611.5
#> M181T436_POS  248764.1   208789.4  423991.8  449021.6  357037.7
#> M345T195_POS        NA  5776921.1        NA        NA        NA
#> M304T825_POS 2816826.6   237776.3  439981.6  510661.8  415109.5
#> M137T196_POS        NA 11028014.0        NA        NA        NA
#> M359T638_POS 1367524.9  1044288.4 1786016.1 1878777.4 1025039.9
#> M270T507_POS  107442.7         NA        NA        NA   60286.3
extract_expression_data(object)
#>                 Blank_3   Blank_4      QC_1      QC_2     PS4P1
#> M136T55_2_POS        NA        NA 1857924.8 1037763.8 1494436.1
#> M79T35_POS           NA        NA 2821550.2 1304875.3 2471336.1
#> M307T548_POS         NA        NA  410387.6  273687.8  288590.2
#> M183T224_POS         NA        NA        NA        NA        NA
#> M349T47_POS          NA        NA 8730104.8 4105598.5 5141073.2
#> M182T828_POS  3761892.6 2572593.4        NA 3662819.1 5700534.8
#> M299T359_POS         NA        NA 3688690.6 2892719.6 1401632.7
#> M348T844_POS         NA        NA        NA 3131157.7        NA
#> M344T471_POS         NA        NA  589957.0  408610.8        NA
#> M181T436_POS   249352.6  131374.5  248764.1  208789.4  423991.8

Session information

sessionInfo()
#> R version 4.2.1 (2022-06-23)
#> Platform: x86_64-apple-darwin17.0 (64-bit)
#> Running under: macOS Big Sur ... 10.16
#> 
#> Matrix products: default
#> BLAS:   /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.2/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] masstools_1.0.2    forcats_0.5.1.9000 stringr_1.4.0      dplyr_1.0.9       
#>  [5] purrr_0.3.4        readr_2.1.2        tidyr_1.2.0        tibble_3.1.7      
#>  [9] ggplot2_3.3.6      tidyverse_1.3.1    magrittr_2.0.3     tinytools_0.9.1   
#> [13] massdataset_1.0.12
#> 
#> loaded via a namespace (and not attached):
#>   [1] readxl_1.4.0                backports_1.4.1            
#>   [3] circlize_0.4.15             systemfonts_1.0.4          
#>   [5] plyr_1.8.7                  lazyeval_0.2.2             
#>   [7] BiocParallel_1.30.3         GenomeInfoDb_1.32.2        
#>   [9] Rdisop_1.56.0               digest_0.6.29              
#>  [11] foreach_1.5.2               yulab.utils_0.0.5          
#>  [13] htmltools_0.5.2             fansi_1.0.3                
#>  [15] memoise_2.0.1               cluster_2.1.3              
#>  [17] doParallel_1.0.17           tzdb_0.3.0                 
#>  [19] openxlsx_4.2.5              limma_3.52.2               
#>  [21] ComplexHeatmap_2.12.0       modelr_0.1.8               
#>  [23] matrixStats_0.62.0          pkgdown_2.0.5              
#>  [25] colorspace_2.0-3            rvest_1.0.2                
#>  [27] textshaping_0.3.6           haven_2.5.0                
#>  [29] xfun_0.31                   crayon_1.5.1               
#>  [31] RCurl_1.98-1.7              jsonlite_1.8.0             
#>  [33] impute_1.70.0               iterators_1.0.14           
#>  [35] glue_1.6.2                  gtable_0.3.0               
#>  [37] zlibbioc_1.42.0             XVector_0.36.0             
#>  [39] GetoptLong_1.0.5            DelayedArray_0.22.0        
#>  [41] shape_1.4.6                 BiocGenerics_0.42.0        
#>  [43] scales_1.2.0                vsn_3.64.0                 
#>  [45] DBI_1.1.3                   Rcpp_1.0.8.3               
#>  [47] mzR_2.30.0                  viridisLite_0.4.0          
#>  [49] clue_0.3-61                 gridGraphics_0.5-1         
#>  [51] preprocessCore_1.58.0       stats4_4.2.1               
#>  [53] MsCoreUtils_1.8.0           htmlwidgets_1.5.4          
#>  [55] httr_1.4.3                  RColorBrewer_1.1-3         
#>  [57] ellipsis_0.3.2              pkgconfig_2.0.3            
#>  [59] XML_3.99-0.10               sass_0.4.1                 
#>  [61] dbplyr_2.2.1                utf8_1.2.2                 
#>  [63] ggplotify_0.1.0             tidyselect_1.1.2           
#>  [65] rlang_1.0.3                 munsell_0.5.0              
#>  [67] cellranger_1.1.0            tools_4.2.1                
#>  [69] cachem_1.0.6                cli_3.3.0                  
#>  [71] generics_0.1.3              broom_1.0.0                
#>  [73] evaluate_0.15               fastmap_1.1.0              
#>  [75] mzID_1.34.0                 yaml_2.3.5                 
#>  [77] ragg_1.2.2                  knitr_1.39                 
#>  [79] fs_1.5.2                    zip_2.2.0                  
#>  [81] ncdf4_1.19                  pbapply_1.5-0              
#>  [83] xml2_1.3.3                  compiler_4.2.1             
#>  [85] rstudioapi_0.13             plotly_4.10.0              
#>  [87] png_0.1-7                   affyio_1.66.0              
#>  [89] reprex_2.0.1                bslib_0.3.1                
#>  [91] stringi_1.7.6               desc_1.4.1                 
#>  [93] MSnbase_2.22.0              lattice_0.20-45            
#>  [95] ProtGenerics_1.28.0         Matrix_1.4-1               
#>  [97] ggsci_2.9                   vctrs_0.4.1                
#>  [99] pillar_1.7.0                lifecycle_1.0.1            
#> [101] BiocManager_1.30.18         jquerylib_0.1.4            
#> [103] MALDIquant_1.21             GlobalOptions_0.1.2        
#> [105] data.table_1.14.2           bitops_1.0-7               
#> [107] GenomicRanges_1.48.0        R6_2.5.1                   
#> [109] pcaMethods_1.88.0           affy_1.74.0                
#> [111] IRanges_2.30.0              codetools_0.2-18           
#> [113] MASS_7.3-57                 assertthat_0.2.1           
#> [115] SummarizedExperiment_1.26.1 rprojroot_2.0.3            
#> [117] rjson_0.2.21                withr_2.5.0                
#> [119] S4Vectors_0.34.0            GenomeInfoDbData_1.2.8     
#> [121] parallel_4.2.1              hms_1.1.1                  
#> [123] grid_4.2.1                  rmarkdown_2.14             
#> [125] MatrixGenerics_1.8.1        Biobase_2.56.0             
#> [127] lubridate_1.8.0