checkExists {oligoClasses} | R Documentation

## Checks to see whether an object exists and, if not, executes the appropriate function.

### Description

Only loads an object if the object name is not in the global environment. If not in the global environment and the file exists, the object is loaded (by default). If the file does not exist, the function FUN is run.

### Usage

    checkExists(.name, .path = ".", .FUN, .FUN2, .save.it=TRUE, .load.it, ...)

### Arguments

`.name` | Character string giving name of object in global environment
`.path` | Path to where the object is saved.
`.FUN` | Function to be executed if <name> is not in the global environment and the file does not exist.
`.FUN2` | Not currently used.
`.save.it` | Logical. Whether to save the object to the directory indicaged by `path`. This argument is ignored if the object was loaded from file or already exists in the .GlobalEnv.
`.load.it` | Logical. If load.it is TRUE, we try to load the object from the indicated `path`. The returned object will replace the object in the .GlobalEnv unless the object is bound to a different name (symbol) when the function is executed.
`...` | Additional arguments passed to FUN.

### Value

Could be anything – depends on what FUN, FUN2 perform.

Future versions could return a 0 or 1 indicating whether the function performed as expected.

### Author(s)

R. Scharpf

### Examples

    path <- tempdir()
    dir.create(path)
    x <- 3+6
    x <- checkExists("x", .path=path, .FUN=function(y, z) y+z, y=3, z=6)
    rm(x)
    x <- checkExists("x", .path=path, .FUN=function(y, z) y+z, y=3, z=6)
    rm(x)
    x <- checkExists("x", .path=path, .FUN=function(y, z) y+z, y=3, z=6)
    rm(x)
    ##now there is a file called x.rda in tempdir().  The file will be loaded
    x <- checkExists("x", .path=path, .FUN=function(y, z) y+z, y=3, z=6)
    rm(x)
    unlink(path, recursive=TRUE)

[Package oligoClasses version 1.56.0 Index]