encode_source: Encode and compress a file or string

View source: R/ascii_encoding.R

encode_sourceR Documentation

Encode and compress a file or string

Description

A helper function for encoding and compressing a file or string to ASCII using base91_encode() and qserialize() with the highest compression level.

Usage

encode_source(x = NULL, file = NULL, width = 120)

Arguments

x

The object to encode (if file is not NULL)

file

The file to encode (if x is not NULL)

width

The output will be broken up into individual strings, with width being the longest allowable string.

Details

The encode_source() and decode_source() functions are useful for storing small amounts of data or text inline to a .R or .Rmd file.

Value

A character vector in base91 representing the compressed original file or object.

Examples

set.seed(1); data <- sample(500)
result <- encode_source(data)
# Note: the result string is not guaranteed to be consistent between qs or zstd versions
#       but will always properly decode regardless
print(result)
result <- decode_source(result) # [1]  1  2  3  4  5  6  7  8  9 10

qs documentation built on Oct. 2, 2024, 1:07 a.m.