5.5 Saving and Loading an ArchRProject

ArchR provides a facile way to save an ArchRProject object to either re-load at a later time or share with other users. Fundamentally, an ArchRProject points to a set of Arrow files. Because of this, the process of saving an ArchRProject using the saveArchRProject() function will:

  1. Copy the current Arrow files and other associated project files to the designated outputDirectory so that they are exclusively associated with the new ArchRProject object.
  2. Save a copy of the designated ArchRProject in the outputDirectory.

For example, we can save our projHeme1 using saveArchRProject() which will allow us to use this project in future chapters.

projHeme1 <- saveArchRProject(ArchRProj = projHeme1, outputDirectory = "Save-ProjHeme1", load = TRUE)
## Copying ArchRProject to new outputDirectory : /corces/home/rcorces/scripts/github/ArchR_Website_Testing/bookdown/Save-ProjHeme1
## Copying Arrow Files...
## Copying Arrow Files (1 of 3)
## Copying Arrow Files (2 of 3)
## Copying Arrow Files (3 of 3)
## Getting ImputeWeights
## No imputeWeights found, returning NULL
## Copying Other Files...
## Copying Other Files (1 of 1): Plots
## Saving ArchRProject...
## Loading ArchRProject...
## Successfully loaded ArchRProject!
## 
##                                                    / |
##                                                  /    \
##             .                                  /      |.
##             \\\                              /        |.
##               \\\                          /           `|.
##                 \\\                      /              |.
##                   \                    /                |\
##                   \\#####\           /                  ||
##                 ==###########>      /                   ||
##                  \\##==......\    /                     ||
##             ______ =       =|__ /__                     ||      \\\
##         ,--' ,----`-,__ ___/'  --,-`-===================##========>
##        \               '        ##_______ _____ ,--,__,=##,__   ///
##         ,    __==    ___,-,__,--'#'  ==='      `-'    | ##,-/
##         -,____,---'       \\####\\________________,--\\_##,/
##            ___      .______        ______  __    __  .______      
##           /   \     |   _  \      /      ||  |  |  | |   _  \     
##          /  ^  \    |  |_)  |    |  ,----'|  |__|  | |  |_)  |    
##         /  /_\  \   |      /     |  |     |   __   | |      /     
##        /  _____  \  |  |\  \\___ |  `----.|  |  |  | |  |\  \\___.
##       /__/     \__\ | _| `._____| \______||__|  |__| | _| `._____|
## 

This will copy the Arrow files and save a .RDS file of the projHeme1 ArchRProject object in the specified outputDirectory. The saveArchRProject() function also has the dropCells parameter. If dropCells = TRUE then cells that exist within the ArrowFiles but have been otherwise removed from the ArchRProject will be trimmed from the ArrowFiles before they are copied to the outputDirectory.

Very important! The load parameter determines whether or not the saveArchRProject() function will return the saved ArchRProject object which you would assign to overwrite the original ArchRProject object or provide a new ArchRProject name using <-. This effectively saves and loads the ArchRProject from its new location. If load = FALSE, then this process does NOT update the ArchRProject object that is active in your current R session. Specifically, the object named projHeme1 in the current R session will still point to the original location of the Arrow files, not the copied Arrow files that reside in the specified outputDirectory. You might use this behavior if you were saving your ArchRProject and shutting down your R session so that the project can be reloaded at a later time.

Also important! The term ArchRProject can be confusing to some users because we use this both to refer to the object that is actively loaded within the R environment and to the file that has been saved on disk as part of the saveArchRProject() process. However, it is extremely important to understand that these are not equivalent. Manipulations that you perform on an ArchRProject that is actively loaded within the R environment do not automatically propagate to the on-disk file. You must run the saveArchRProject() function to store those changes.

To load an ArchRProject that has been previously saved using saveArchRProject() we would use the loadArchRProject() function. To do this, we must provide the path to the directory containing the ArchRProject object which is stored in a file named Save-ArchR-Project.rds.

For example, the above call to saveArchRProject() would have created a directory named Save-ProjHeme1 with the following contents:

list.files(path = "./Save-ProjHeme1")
## [1] "ArrowFiles"             "Embeddings"             "ImputeWeights"         
## [4] "IterativeLSI"           "IterativeLSI2"          "Plots"                 
## [7] "RNAIntegration"         "Save-ArchR-Project.rds"

To load this project we would therefore run:

projHeme1 <- loadArchRProject(path = "./Save-ProjHeme1")
## Successfully loaded ArchRProject!
## 
##                                                    / |
##                                                  /    \
##             .                                  /      |.
##             \\\                              /        |.
##               \\\                          /           `|.
##                 \\\                      /              |.
##                   \                    /                |\
##                   \\#####\           /                  ||
##                 ==###########>      /                   ||
##                  \\##==......\    /                     ||
##             ______ =       =|__ /__                     ||      \\\
##         ,--' ,----`-,__ ___/'  --,-`-===================##========>
##        \               '        ##_______ _____ ,--,__,=##,__   ///
##         ,    __==    ___,-,__,--'#'  ==='      `-'    | ##,-/
##         -,____,---'       \\####\\________________,--\\_##,/
##            ___      .______        ______  __    __  .______      
##           /   \     |   _  \      /      ||  |  |  | |   _  \     
##          /  ^  \    |  |_)  |    |  ,----'|  |__|  | |  |_)  |    
##         /  /_\  \   |      /     |  |     |   __   | |      /     
##        /  _____  \  |  |\  \\___ |  `----.|  |  |  | |  |\  \\___.
##       /__/     \__\ | _| `._____| \______||__|  |__| | _| `._____|
##