Workflow

scratch_capture

Capture and Save Data to File

Saves data to a file in various formats based on the object type and specified format. If no name is provided, uses the name of the object passed in. If no location is provided, uses the scratch directory from the configuration.


Usage

scratch_capture(x, name = NULL, to = NULL, location = NULL, n = Inf)

Arguments

Argument Description
x

The object to save

name

Optional character string specifying the name of the file (without extension). If not provided, will use the name of the object passed in.

to

Optional character string indicating the output format. One of: "text", "rds", "csv", "tsv". If not provided, will choose based on object type.

location

Optional character string specifying the directory where the file should be saved. If NULL, uses the scratch directory from the configuration.

n

Optional number of rows to capture for data frames (default: all rows)

Returns

The input object x invisibly.

Examples

# Save a character vector as text
scratch_capture(c("hello", "world"))

# Save a data frame as TSV
scratch_capture(mtcars)

# Save an R object as RDS
scratch_capture(list(a = 1, b = 2), to = "rds")

Source: R/scratch.R