redo.if: Run code if redo variable is TRUE

View source: R/redo_if.R

redo.ifR Documentation

Run code if redo variable is TRUE

Description

Basically executes an IF/ELSE statement to either re-run code (if the redo variable is TRUE) or return data saved in an RDS file (if the redo variable is FALSE).

Usage

redo.if(
  redo.var,
  save.file = NULL,
  code,
  force = FALSE,
  max.save.mb = 10,
  lf.dir = "Large_files"
)

Arguments

redo.var

character; The redo variable name you want to reference.

save.file

character; The RDS file to which you want to save the results or from which you want to read prior results. If '.rds' is not at the end of the file, it will be appended.

code

The code (in curly brackets) you want to execute within the statement which should produce the object you want to return and save when the redo variables is TRUE.

max.save.mb

integer; the file size (in megabytes) at which a saved file will trigger a prompt to move it to the 'lf.dir'

lf.dir

character; the name of the directory to move files larger than 'max.save.mb' to. Default is "Large_files"

Examples

chunk.names <- c("chunk1", "chunk2")

assign.redo(chunk.names)

toggle.redo("chunk1")

if (redo$chunk1) {
  x <- rnorm(100)
} else {
  x <- data(example_data1)
}

x <- redo.if("chunk1", save.file = "test_file.rds", {rnorm(50)})

kstagaman/redoControl documentation built on April 6, 2022, 8:04 a.m.