R/options.R
n2khab_options.Rd
The package can be configured by means of options or environment variables. These will influence the behaviour of certain functions. Each option has its sibling environment variable. When both have a value, the option will be given priority.
This function queries these options and environment variables, and returns the resulting state for each of them (not distinguishing between options or environment variables as the source).
n2khab_options()
A data frame with the names and values of possible options.
Missing values are returned as NA
.
Options are typically harder to
isolate from the R code that you collaborate on and share through a
repository.
This is especially the case when using renv
: it requires
.Rprofile
as part of your project in the working directory, which prevents
.Rprofile
files elsewhere on the system from being used.
Consequently, it is advised to:
use options()
where this affects behaviour that must be the same across
users and machines for reproducibility.
Put these inside your script, or at least in an .Rprofile
file that is
shared together with the other project files.
Example: which package to use to represent raster objects.
use environment variables where behaviour must be machine-specific, e.g.
to override the default location of the n2khab_data
directory (can also be
needed when using reprex::reprex()
).
For example, you can create an .Renviron
file in your working directory
and ignore it in distributed version control.
Or you can set the environment variable at a higher level, e.g. in an
.Renviron
file in your home directory.
See base::Startup for more information.
option | environment variable | type | description |
n2khab_data_path | N2KHAB_DATA_PATH | string | Path of the n2khab_data directory. Takes priority over the default locations where reading functions expect this directory. |
n2khab_use_raster | N2KHAB_USE_RASTER | logical | Should the raster package be used to return raster objects? The terra package is used by default. |
n2khab_options() #> # A tibble: 2 × 2 #> option value #> <chr> <chr> #> 1 n2khab_data_path NA #> 2 n2khab_use_raster NA oldopt <- options(n2khab_use_raster = TRUE) n2khab_options() #> # A tibble: 2 × 2 #> option value #> <chr> <chr> #> 1 n2khab_data_path NA #> 2 n2khab_use_raster TRUE options(oldopt) # Unacceptable values yield an error message; # the data frame is still returned with NA: oldopt <- options(n2khab_data_path = 0, n2khab_use_raster = TRUE) n2khab_options() #> Error: Option 'n2khab_data_path' must be a string. #> # A tibble: 2 × 2 #> option value #> <chr> <chr> #> 1 n2khab_data_path NA #> 2 n2khab_use_raster TRUE options(oldopt)