Establish a temporary working tree for testing app-building functionality.
Source:R/build.R
in_tmp_env.Rd
This function creates a temporary autocv
project directory with a
working tree mirroring that of the user's, which is defined in their
.Rprofile file. This temporary directory serves as an environment
for testing the following application-building functionality:
building applications
rendering applications
accessing application logs
running application keyword checks
See also
Other build-dev:
as_filename()
,
construct_app_metadata()
,
copy_files()
,
create_rprofile()
,
create_rproject()
,
get_latest_entry()
,
get_valid_opts()
,
open_doc_and_wait()
,
set_project_paths()
,
str_to_filename()
,
truncate_string()
,
validate_id()
,
validate_status()
,
write_app_metadata()
Examples
# Set temporary path environment variables ----------------------------------
in_tmp_env(message("Temporary root directory: ", Sys.getenv("ROOT")))
#> Temporary root directory: /tmp/RtmpxhNRJk
message("Reset root directory: ", Sys.getenv("ROOT"))
#> Reset root directory: /home/runner/work/autocv/autocv
in_tmp_env(message("Temporary templates loc: ", get_path_to("templates")))
#> Temporary templates loc: /home/runner/.cache/R/renv/library/autocv-e7350c3b/linux-ubuntu-jammy/R-4.4/x86_64-pc-linux-gnu/autocv/templates
message("Reset templates loc: ", get_path_to("templates"))
#> Reset templates loc: /home/runner/.cache/R/renv/library/autocv-e7350c3b/linux-ubuntu-jammy/R-4.4/x86_64-pc-linux-gnu/autocv/templates
# Wrap multi-line expressions -----------------------------------------------
in_tmp_env({
x <- c(1, 2, 3)
for (i in x) {
print(i)
}
})
#> [1] 1
#> [1] 2
#> [1] 3
# Handle input/output operations in the temporary environment ---------------
in_tmp_env({
tmpdir <- get_path_to("input")
if (!dir.exists(tmpdir)) {
dir.create(tmpdir, recursive = TRUE)
}
fil <- file.path(tmpdir, "test.txt")
con <- file(fil, open = "w")
writeLines("this is a test", con = con)
close(con)
cat(paste0("In ", cli::col_blue(fil), ":\n", readLines(fil)))
})
#> In /tmp/RtmpxhNRJk/./R/input/test.txt:
#> this is a test