Title: | Dynamic Settings File |
---|---|
Description: | Any package (subsequently called 'target package') is enabled to provide its users an easily accessible, user-friendly and human readable text file where key=value pairs (used by functions defined in the target package) can be saved. This settings file lives in a location defined by the user of the target package, and its user-defined values remain unchanged even when the author of the target package is introducing or deleting keys, or when the target package is updated or re-installed. |
Authors: | Bernhard Pollner [cre, aut], Zoltan Kovacs [aut] |
Maintainer: | Bernhard Pollner <[email protected]> |
License: | GPL (>=3) |
Version: | 0.3.2 |
Built: | 2025-03-11 04:16:48 UTC |
Source: | https://github.com/bpollner/uniset |
Any package (subsequently called 'target package') is enabled to provide its users an easily accessible, user-friendly and human readable text file where key=value pairs (used by functions defined in the target package) can be saved. This settings file lives in a location defined by the user of the target package, and its user-defined values remain unchanged even when the author of the target package is introducing or deleting keys, or when the target package is updated or re-installed. In order to enable the target package to make use of the functionality offered by package 'uniset', three files have to be exported by 'uniset' and placed into the target package.
There are two ways to generate the files required for the target package to make use of 'uniset':
Use uniset_getFiles
, then move
the 'xxx_settings.R' file ('xxx' for the name of the target package) into the
'inst' folder (create one if not already done) of the target package.
Move the files 'uniset_globals.R' and 'uniset_functions.R' into the
'R' folder of the target package.
(Recommended) Use
uniset_copyFilesToPackage
to copy the required files directly into
the target package.
Every variable defined in the xxx_settings.R file is accessible in the code of
the target package.
The target package has to list 'uniset' as an 'import', and then
uniset_updateSettings
or uniset_autoUpS
can be used
to manually or automatically update the settings,i.e. to read in the key=value
pairs stored in the xxx_settings.R file.
For an introduction and more detailed information please see
https://bpollner.github.io/uniset/.
The most imminent advantage of the 'uniset' settings-file
system over using any static file for permanently storing settings for any
package is the fact that the key=value pairs in the xxx_settings.R
file get updated (added / deleted) dynamically.
So the developer of a package can delete keys or introduce new ones, and
the new key=value pairs will be automatically added to or deleted from
the local xxx_settings.R file. Values changed by the user of the
target package will be preserved.
So the author of the target package can add or delete keys from the
xxx_settings.R file without worrying that this will cause any effort or
troubles for the user of the target package.
Please see https://bpollner.github.io/uniset/ for a practical example; bug reports can be made at https://github.com/bpollner/uniset/issues.
Bernhard Pollner [email protected]
uniset_copyFilesToPackage
, uniset_getFiles
uniset_autoUpS
, uniset_updateSettings
,
uniset_test
, uniset_getstn
,
and only once: uniset_setup
.
As the functions to update the settings file and to (automatically) source this settings are intended to be called from within the (installed) target package, please go to https://bpollner.github.io/uniset/ for a walk-through and for a real-life demonstration and examples how to use these functions in the code of the target package.
Bernhard Pollner, Zoltan Kovacs
Use this function within your code to automatically update the settings from the users settings file
uniset_autoUpS(uniset_handover, setupFunc = NULL)
uniset_autoUpS(uniset_handover, setupFunc = NULL)
uniset_handover |
List length two, containing two elements:
|
setupFunc |
Character length one. The name of the function in the target
package performing the setup, i.e. the name of the function that is
containing the |
If 'autoUpdateSettings' in the local settings.R file is left at 'TRUE',
the settings will be checked resp. updated automatically every time a function
in the target package is calling uniset_autoUpS
.
Is primarily called for its side effects, i.e to automatically update / (re-)source the settings file. Returns (invisible) 'FALSE' if the the update was unsuccessful, otherwise an (invisible) list with the settings sourced from the settings.R file.
This function is meant to be called from within the target package.
Please refer to uniset
for a link to examples
and a real-world demo.
{ ## Not run: # to be called from within the target package uniset_autoUpS(uniset_handover, "dogPack_demo_setup") ## End(Not run) }
{ ## Not run: # to be called from within the target package uniset_autoUpS(uniset_handover, "dogPack_demo_setup") ## End(Not run) }
Generate the four files required in the target package (i.e. the package that should be enabled to use the package 'uniset'). The generated files will be copied directly into their required destination folders in the target package. The name of the target package will be extracted from the description file.
uniset_copyFilesToPackage( pathToPackage, setupFunc = NULL, taPaSH = "def", taPaObj = "settings", tmpl = "_TEMPLATE" )
uniset_copyFilesToPackage( pathToPackage, setupFunc = NULL, taPaSH = "def", taPaObj = "settings", tmpl = "_TEMPLATE" )
pathToPackage |
Character length one. The path to the root of the target package. |
setupFunc |
Character length one. The name of the function
in the target package that is containing the setup-function
|
taPaSH |
Character length one. The name of the variable to be defined in
the '.Renviron' file, leading to the place where the settings.R file for the
target package will be stored. If left at the default 'def', |
taPaObj |
Character length one. The name of the object holding the list with the key-value pairs that can be defined to be used in the target package. Can be left at the default 'settings'. |
tmpl |
Character length one. the Character string that will be appended to the fresh settings file that is copied (by the target package) to the users settings home directory if updating the key=value pairs was not successful. Can be left at the default '_TEMPLATE'. |
Writes the four required files directly into a valid R-package folder structure. Returns (invisible) NULL.
Please refer to uniset
for a link to examples
and a real-world demo.
{ library(uniset) # first copy the target package example into tempdir to <- tempdir() from <- paste0(path.package("uniset"), "/examples/dogPack") file.copy(from, to, recursive = TRUE) # now copy the four required files directly into the package 'dogPack' path <- paste0(to, "/dogPack") uniset_copyFilesToPackage(path, "nameOfSetupFunc") }
{ library(uniset) # first copy the target package example into tempdir to <- tempdir() from <- paste0(path.package("uniset"), "/examples/dogPack") file.copy(from, to, recursive = TRUE) # now copy the four required files directly into the package 'dogPack' path <- paste0(to, "/dogPack") uniset_copyFilesToPackage(path, "nameOfSetupFunc") }
Function to generate the four files required in the target package (i.e. the package that should be enabled to use the package 'uniset').
uniset_getFiles( taPaName = NULL, setupFunc = NULL, where = NULL, taPaSH = "def", taPaObj = "settings", tmpl = "_TEMPLATE" )
uniset_getFiles( taPaName = NULL, setupFunc = NULL, where = NULL, taPaSH = "def", taPaObj = "settings", tmpl = "_TEMPLATE" )
taPaName |
Character length one. The name of the target package. |
setupFunc |
Character length one. The name of the function
in the target package that is containing the setup-function
|
where |
Character length one. The location where the folder with the resulting four files should be copied to. Defaults to 'NULL'. If left at the default 'NULL', the location should be selectable interactively. Provide a character length one holding a valid path to an existing folder to copy the folder containing the four required files there. |
taPaSH |
Character length one. The name of the variable to be defined in
the '.Renviron' file, leading to the place where the settings.R file for the
target package will be stored. If left at the default 'def', |
taPaObj |
Character length one. The name of the object holding the list with the key-value pairs that can be defined to be used in the target package. Can be left at the default 'settings'. |
tmpl |
Character length one. the Character string that will be appended to the fresh settings file that is copied (by the target package) to the users settings home directory if updating the key=value pairs was not successful. Can be left at the default '_TEMPLATE'. |
Look at the content of the four generated files for information on where they should be moved.
Creates a folder at the location specified at argument 'where' with the four files to be moved into the target package in it. Returns an (invisible) character holding the path of the folder where the three files were written into.
Please refer to uniset
for a link to examples
and a real-world demo.
{ library(uniset) # first copy the target package example into tempdir to <- tempdir() from <- paste0(path.package("uniset"), "/examples/dogPack") file.copy(from, to, recursive = TRUE) # now copy the four required files uniset_getFiles("dogPack", setupFunc="nameOfSetupFunc", where=to) # Now manually move the four files according to the instructions contained # in them. }
{ library(uniset) # first copy the target package example into tempdir to <- tempdir() from <- paste0(path.package("uniset"), "/examples/dogPack") file.copy(from, to, recursive = TRUE) # now copy the four required files uniset_getFiles("dogPack", setupFunc="nameOfSetupFunc", where=to) # Now manually move the four files according to the instructions contained # in them. }
Get Settings Object description Source the list holding the key=value pairs from the settings.R file.
uniset_getstn(uniset_handover)
uniset_getstn(uniset_handover)
uniset_handover |
List length two, containing two elements:
|
A list holding the key=value pairs from the settings.R file on on success, NULL if sourcing the file was not successful.
This function is meant to be called from within the target package.
{ ## Not run: # to be called from within the target package uniset_getstn(uniset_handover) ## End(Not run) }
{ ## Not run: # to be called from within the target package uniset_getstn(uniset_handover) ## End(Not run) }
Perform the required setup to enable the target package to make use of the functionality of package 'uniset'. Only has to be called once by the user of the target package.
uniset_setup(where = NULL, uniset_handover)
uniset_setup(where = NULL, uniset_handover)
where |
Character length one, holding the path to the location where the
folder containing the settings.R file should be located. Defaults to 'NULL'.
The path has to be given either in forward-slashes ( |
uniset_handover |
List length two, containing two elements:
|
This function is intended to be called from within the target package by the user of the target package. Only has to be called once to initiate the system, i.e. to
Define the folder where the settings.R file will be located,
Copy the settings.R file into this folder, and
Create a corresponding entry in the .Renviron file (or create the .Renviron file if does not exist).
This setup has to be done manually (but only once!) by the user of the target package. However, if called repeatedly, it enables the user of the target package to conveniently change the settings-home directory and its corresponding variable in the .Renviron file. In that case, a factory-fresh version of the settings.R file will be copied into the new settings-home directory. For the user-defined values in the 'old' settings.R file not to be lost, the user then has to manually move / copy the settings from the old location to the new one.
Called for its side effects, i.e. to initiate the dynamic settings file system (see Details.) Returns an (invisible) character length one holding the path to the settings-home directory.
This function is meant to be called from within the target package.
{ ## Not run: # to be called from within the target package uniset_setup(where, uniset_handover) ## End(Not run) }
{ ## Not run: # to be called from within the target package uniset_setup(where, uniset_handover) ## End(Not run) }
Test if the input package name etc. was correct / successful. This function is meant to be called from inside the target package.
uniset_test(uniset_handover)
uniset_test(uniset_handover)
uniset_handover |
List length two, containing two elements:
|
Is printing the parameters defined by the target package, and is returning those parameters in an (invisible) list.
This function is intended to be called from within the target package.
Please refer to uniset
for a link to examples
and a real-world demo.
{ ## Not run: # to be called from within the target package uniset_test(uniset_handover) ## End(Not run) }
{ ## Not run: # to be called from within the target package uniset_test(uniset_handover) ## End(Not run) }
Manually read in the settings-file in the target package settings home directory as specified in the .Renviron file.
uniset_updateSettings(uniset_handover, setupFunc = NULL, silent = FALSE)
uniset_updateSettings(uniset_handover, setupFunc = NULL, silent = FALSE)
uniset_handover |
List length two, containing two elements:
|
setupFunc |
Character length one. The name of the function in the target
package performing the setup, i.e. the name of the function that is
containing the |
silent |
Logical. If a confirmation should be printed. Defaults to 'FALSE' |
This function is called for its side effects, i.e to manually update / (re-)source the settings file. Returns (invisible) 'FALSE' if the update was unsuccessful, otherwise an (invisible) list with the settings sourced from the settings.R file.
This function is meant to be called from within the target package.
Please refer to uniset
for a link to examples
and a real-world demo.
{ ## Not run: # to be called from within the target package uniset_updateSettings(uniset_handover, "dogPack_demo_setup") ## End(Not run) }
{ ## Not run: # to be called from within the target package uniset_updateSettings(uniset_handover, "dogPack_demo_setup") ## End(Not run) }