File: quickLoadObject.R

package info (click to toggle)
r-bioc-alabaster.base 1.6.1%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,652 kB
  • sloc: cpp: 11,377; sh: 29; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 2,081 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#' Convenience helpers for handling local directories
#'
#' \emph{WARNING: these functions are deprecated as the saving/reading functions are already simple enough in the newer versions of the \pkg{alabaster} framework.}
#' Read and write objects from a local staging directory.
#' These are just convenience wrappers around functions like \code{\link{loadObject}}, \code{\link{stageObject}} and \code{\link{writeMetadata}}.
#'
#' @param x Object to be saved.
#' @param dir String containing a path to the directory.
#' @param path String containing a relative path to the object of interest inside \code{dir}.
#' @param ... Further arguments to pass to \code{\link{loadObject}} (for \code{quickLoadObject}) or \code{\link{stageObject}} (for \code{quickStageObject}).
#'
#' @return For \code{quickLoadObject}, the object at \code{path}.
#'
#' For \code{quickStageObject}, the object is saved to \code{path} inside \code{dir}.
#' All necessary directories are created if they are not already present.
#' A \code{NULL} is returned invisibly.
#'
#' @author Aaron Lun
#'
#' @examples
#' local <- tempfile()
#'
#' # Creating a slightly complicated object:
#' library(S4Vectors)
#' df <- DataFrame(A=1:10, B=LETTERS[1:10])
#' df$C <- DataFrame(D=letters[1:10], E=runif(10))
#'
#' # Saving it:
#' quickStageObject(df, local, "FOOBAR")
#'
#' # Reading it back:
#' quickLoadObject(local, "FOOBAR")
#'
#' @export
#' @aliases readLocalObject saveLocalObject
quickLoadObject <- function(dir, path, ...) {
    meta <- acquireMetadata(dir, path)
    loadObject(meta, dir, ...)
}

#' @export
#' @rdname quickLoadObject
quickStageObject <- function(x, dir, path, ...) {
    dir.create(file.path(dir, dirname(path)), recursive=TRUE, showWarnings=FALSE)
    meta <- stageObject(x, dir, path, ...)
    info <- writeMetadata(meta, dir)
    writeMetadata(.createRedirection(dir, path, info$path), dir)
    invisible(NULL)
}

# Soft-deprecated back-compatibility fixes.

#' @export
readLocalObject <- function(...) quickLoadObject(...)

#' @export
saveLocalObject <- function(...) quickStageObject(...)