Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • 187e518
  • /
  • R
  • /
  • loadPreloaded.R
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:a4c4509181288e86706ecaeba62642b982b7b48d
directory badge
swh:1:dir:2feb2dfe690666d08df4dc2e74db516daa33b3bb

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
loadPreloaded.R
#' Load GEO Dataset.
#'
#' \code{loadPreloaded} returns the file with serialized ExpressionSets using
#'     ProtoBuf, that were preloaded on server.
#'
#' @param name String, containing filename. Assuming
#'     that in the directory with preloaded files \code{preloadedDir}
#'     exists file \code{filename.rda} with list of ExpressionSets \code{ess}.
#'
#'
#' @return File with ProtoBuf-serialized ExpressionSet-s
#'     that were loaded from specified file.
#'
#' @import Biobase
loadPreloaded <- function(name) {
    preloadedDir <- getOption("phantasusPreloadedDir")
    cacheDir <- getOption("phantasusCacheDir")
    if (is.null(preloadedDir)) {
        stop("Specify the directory with presaved files")
    } else if (!dir.exists(preloadedDir)) {
        stop("No such directory")
    }

    fileToLoad <- file.path(preloadedDir, paste0(name, '.rda'))
    if (!file.exists(fileToLoad)) {
        stop('No such dataset')
    }

    x <- load(fileToLoad) # must return the object ess
    loaded <- get(x)

    wrongFormat <- paste("Wrong format.",
                            "File must contain either ExpressionSet",
                            "or list of ExpressionSets")

    ess <- NULL

    if (class(loaded) == "ExpressionSet") {
        ess <- list()
        ess[[name]] <- loaded
    } else if (class(loaded) == "list") {
        ess <- loaded
        if (!all(unlist(lapply(loaded, class)) == "ExpressionSet")) {
            stop(wrongFormat)
        }
    } else {
        stop(wrongFormat)
    }

    files <- list()
    assign("es", ess[[1]], envir = parent.frame())
    files[[name]] <- writeToList(ess[[1]])
    path <- NULL

    if (is.null(cacheDir)) {
        cacheDir <- tempdir()
    }

    preloadedCacheDir <- file.path(cacheDir, 'preloaded')
    binaryName <- paste0(name, '.bin')
    dir.create(preloadedCacheDir, showWarnings = FALSE, recursive = TRUE)



    cachedFile <- file.path(preloadedCacheDir, binaryName)
    dir.create(dirname(cachedFile), showWarnings = FALSE, recursive = TRUE)
    if (!file.exists(cachedFile) ||
        file.info(cachedFile)$ctime < file.info(fileToLoad)$ctime) {
        writeBin(protolite::serialize_pb(files), cachedFile)
    }

    path <- paste0('/preloaded/', binaryName)

    jsonlite::toJSON(path)

}

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API