Learn R Programming

envsetup (version 0.3.0)

write_path: Retrieve a file path from an envsetup object containing paths

Description

Paths will be filtered to produce the lowest available level from a hierarchy of paths based on envsetup_environ

Usage

write_path(
  lib,
  filename = NULL,
  envsetup_environ = Sys.getenv("ENVSETUP_ENVIRON"),
  envir = getOption("envsetup.path.environment")
)

Value

path to write

Arguments

lib

Object containing the paths for all environments of a directory

filename

Name of the file you would like to write

envsetup_environ

Name of the environment to which you would like to write. Defaults to the ENVSETUP_ENVIRON environment variable

envir

The environment to search for the path object. Defaults to the value of getOption("envsetup.path.environment").

Examples

Run this code
tmpdir <- tempdir()

# account for windows
if (Sys.info()['sysname'] == "Windows") {
  tmpdir <- gsub("\\", "\\\\", tmpdir, fixed = TRUE)
}

# add config for just the data location
hierarchy <- paste0("default:
  paths:
    data: !expr list(
      DEV = file.path('",tmpdir,"', 'demo', 'DEV', 'username', 'project1', 'data'),
      PROD = file.path('",tmpdir,"', 'demo', 'PROD', 'project1', 'data'))")

# write config file to temp directory
writeLines(hierarchy, file.path(tmpdir, "hierarchy.yml"))

config <- config::get(file = file.path(tmpdir, "hierarchy.yml"))

# build folder structure from config
build_from_config(config)

# setup environment based on config
rprofile(config::get(file = file.path(tmpdir, "hierarchy.yml")))

# find location to write mtcars.rds
write_path(data, "mtcars.rds")

# save data in data folder using write_path
saveRDS(mtcars, write_path(data, "mtcars.rds"))

Run the code above in your browser using DataLab