Return path to metabodecon's data directory
datadir.Rd
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.
Arguments
- file
Relative path to a file within the data directory.
- warn
Print a warning message when the requested path does not yet exist?
- persistent
Return the path to the persistent data directory instead of the temporary one?
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 (or during installation in the location pointed to by TMPDIR: and such usage should be cleaned up). Installing into the system's R installation (e.g., scripts to its bin directory) is not allowed.
Limited exceptions may be allowed in interactive sessions if the package obtains confirmation from the user.
For R version 4.0 or later (hence a version dependency is required or only conditional use is possible), packages may store user-specific data, configuration and cache files in their respective user directories obtained from tools::R_user_dir(), provided that by default sizes are kept as small as possible and the contents are actively managed (including removing outdated material).
Examples
# Return path to persistent data dir if it exists, else path to temp data dir
datadir()
#> Warning: /tmp/RtmplbJ427/metabodecon/data does not exist. Please call `download_example_datasets()` first.
#> [1] "/tmp/RtmplbJ427/metabodecon/data"
# Return path to temporary data directory
datadir(persistent = FALSE)
#> Warning: /tmp/RtmplbJ427/metabodecon/data does not exist. Please call `download_example_datasets()` first.
#> [1] "/tmp/RtmplbJ427/metabodecon/data"
# Return path to persistent data directory
datadir(persistent = TRUE)
#> Warning: /home/runner/.local/share/R/metabodecon does not exist. Please call `download_example_datasets()` first.
#> [1] "/home/runner/.local/share/R/metabodecon"
# Return path to "<persistent-data-dir>/bruker/urine" if it exists.
# Else return path to "<temp-data-dir>/bruker/urine"
datadir(file = "bruker/urine")
#> Warning: /tmp/RtmplbJ427/metabodecon/data/bruker/urine does not exist. Please call `download_example_datasets()` first.
#> [1] "/tmp/RtmplbJ427/metabodecon/data/bruker/urine"