make.fun.club: Creates fun.club workflow manager

View source: R/fun.club.R

make.fun.clubR Documentation

Creates fun.club workflow manager

Description

This function creates the workflow manager of the class fun.club which can be used to create fun.objects as described in help('[<-.fun.club'). The workflow will be automatically saved in file. If file already exists when the workflow is created, its content will be read to ... to do: finish

Usage

make.fun.club(
  dir,
  envir = globalenv(),
  extension.selector = function(object) {
     is.gg <- function(x) {
        
    any(c("ggplot", "grob") %in% class(x))
     }
     if (is.gg(object) ||
    is.list(object) && all(lapply(object, is.gg) == TRUE)) {
         c("rds", "pdf")
   
     }
     else if ("data.table" %in% class(object) && all(lapply(object, is.atomic)
    == TRUE) && nrow(object) > 0L) {
         "fst"
     }
     else if ("connection"
    %in% class(object)) {
         "raw"
     }
     else {
         "rds"
     }
 },
  savers = list(rds = c(function(object, file) saveRDS(object, file = file),
    function(file) readRDS(file = file)), fst = c(function(object, file)
    write.fst(object, path = file, compress = 100), function(file) read.fst(path = file,
    as.data.table = TRUE)), raw = c(function(object, file) {
     l <- length(object)
   
     writeBin(object = l, size = 8L)
     writeBin(object = object, con = file(file),
    open = "wb")
 }, function(file) {
     n.bytes <- readBin(con = file, what =
    integer(), n = 1L, size = 8L)
     readBin(con = file, what = raw(), n = n.bytes)

    }), pdf = c(function(object, file) {
     pdf(file)
     if ("grob" %in%
    class(object)) {
         grid.newpage()
         grid.draw(object)
     } else {
   
         suppressWarnings(print(object))
     }
     dev.off()
 })),
  verbose = 2
)

Arguments

dir

The name of the directory where all generated objects are stored. If it exists, all object and fun.club itself will be read from there, otherwise, the directory will be created. The fun.club object is kept in the file "fun.club.dir" in this directory. The files with the objects have the names of the type "dir/ext/fun_n.ext", where ext is the file extension (eg. "rds"), "fun" is the name of the generating function and "n" is a positive integer.

envir

environment where the fun.club and all its fun.links will be created.

extension.selector

The function receiving the object argument and returning the character vector with one or several file extensions corresponding to this object. The object will be saved to as many files as given in this vector and with the corresponding extensions. Eg. the object can be saved to the file with an "rds" extension as an R object and, additionally, to a "pdf" file as a plot. To retrieve the R object from the disk, only the file with the first extension will be used, so the extensions in the example above should be placed in the order "rds", "pdf".

savers

The list containing read / write functions. Every list element is named by the corresponding file extenson and contains the list with either one or two functions. The first function receives the object and the file arguments and saves the object to this file. The second optional function receives only the file argument. It reads the object from this file and returns it. The reading function can be absent if the extension is not supposed to be used for retrieving the R object (eg. the "pdf" extension which is not suitable for that). In this case it never appears first in the character vector returned by the extension.selector function.

verbose

The integer which controls the amount of the printed diagnostic information, from 0 to 3 (default = 2). 0 means no output, 1 - only the information on deleted or updated functions is printed, 2 - additionally, on the deleted and generated objects and on the operations with the files and the directories, 3 - additionally, on the stack content during the generation of the objects. All information is printed using message() function, so it can also be suppressed with suppressMessages(). verbose argument does not affect warnings and errors. The former can be suppressed using suppressWarnings().

Value

created fun.club object (invisibly)

Author(s)

Vladislav BALAGURA balagura@cern.ch


balagura/fun.club documentation built on June 11, 2025, 11:27 p.m.