Skip to contents

save_and_lock() saves a data frame or R object to a file and then locks it using RSA encryption.

Usage

save_and_lock(
  x,
  file,
  type = "rds",
  public_key = here::here(".ssh", "id_rsa.pub"),
  ...
)

Arguments

x

An R object to be saved and locked. If type = "csv", x must be a data.frame.

file

A character string indicating the file path to save the object to.

type

A character string indicating the file type to save the object as. Must be one of "csv" or "rds" (default: "rds").

public_key

(optional) An openssl RSA public key or a character string specifying the public key path. See rsa_keygen() to learn how to create an RSA key pair (default: here::here(".ssh", "id_rsa.pub")).

...

(optional) Additional arguments passed to write_csv or write_rds.

Value

An invisible string containing the locked file path.

See also

Other lock/unlock functions: lock_dir(), lock_file()

Examples

## Creating Keys and Test Object -----

temp_dir <- tempfile("dir")
dir.create(temp_dir)

rsa_keygen(temp_dir)
#>  Keys successfully created at /tmp/RtmpwNDBbf/dir1c0d3bb44fae.

x <- letters

## Locking and Saving Objects -----

x |>
  save_and_lock(
    file = tempfile(),
    type = "rds",
    public_key = file.path(temp_dir, "id_rsa.pub")
  )
#>  Locked file written at /tmp/RtmpwNDBbf/file1c0dd76ed14.lockr.
#> [1] "/tmp/RtmpwNDBbf/file1c0dd76ed14.lockr"