with_sandbox_dir {condathis} | R Documentation |
Execute Code in a Temporary Directory
Description
Runs user-defined code inside a temporary directory, setting up a temporary
working environment. This function is intended for use in examples and tests
and ensures that no data is written to the user's file space.
Environment variables such as HOME
, APPDATA
, R_USER_DATA_DIR
,
XDG_DATA_HOME
, LOCALAPPDATA
, and USERPROFILE
are redirected to
temporary directories.
Usage
with_sandbox_dir(code, .local_envir = base::parent.frame())
Arguments
code |
expression An expression containing the user-defined code to be executed in the temporary environment. |
.local_envir |
environment The environment to use for scoping. |
Details
This function is not designed for direct use by package users. It is primarily used to create an isolated environment during examples and tests. The temporary directories are created automatically and cleaned up after execution.
Value
Returns NULL
invisibly.
Examples
condathis::with_sandbox_dir(print(fs::path_home()))
condathis::with_sandbox_dir(print(tools::R_user_dir("condathis")))