Returns the path to the directory where
download_example_datasets()
stores metabodecon's example data sets or any
file within that directory. By default this directory is a subdirectory of
R's temporary session directory. If persistent
is set to TRUE
, the
directory equals the data directory returned by tools::R_user_dir()
instead.
Details
The decision to use a temporary data dir as default and a persistent one only optionally was made to conform to CRAN package policies, which state that:
Packages should not write in the user's home filespace (including
clipboards), nor anywhere else on the file system apart from the R
session's temporary directory \[...\] Limited exceptions may be allowed
in interactive sessions if the package obtains confirmation from the
user. For R version 4.0 or later \[...\] packages may store user-specific
data, configuration and cache files in their respective user directories
obtained from [tools::R_user_dir()] \[...\].
Examples
# Get temporary datadir and persistent datadir
datadir(persistent = FALSE, warn = FALSE)
#> [1] "/tmp/RtmpuYVEs7/metabodecon/data"
datadir(persistent = TRUE, warn = FALSE)
#> [1] "/home/runner/.local/share/R/metabodecon"
# Get persistent datadir if existing else temp datadir. Set `warn = TRUE`
# to raise a warning if none of the directories exist yet.
datadir(warn = FALSE)
#> [1] "/tmp/RtmpuYVEs7/metabodecon/data"
if (interactive()) datadir()
# Get PERSISTENT_DATADIR/bruker if existing else TEMP_DATADIR/bruker
datadir(file = "bruker/urine", warn = FALSE)
#> [1] "/tmp/RtmpuYVEs7/metabodecon/data/bruker/urine"