Skip to content

Commit

Permalink
Dev (#55)
Browse files Browse the repository at this point in the history
* Hotfix: malformed path on Windows systems
* Added example to writeUserConfig
* Version -> 2.3.1
  • Loading branch information
Thomas-Caspar-Fischer committed Jul 24, 2023
1 parent d423745 commit c7767b9
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: statR
Title: statR
Version: 2.3.0
Version: 2.3.1
Authors@R: as.person(c(
"Andrea Schnell <andrea.schnell@statistik.ji.zh.ch> [aut]",
"Michelle Donzallaz <michelle.donzallaz@statistik.ji.zh.ch> [aut]",
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# statR 2.3.1

## Bugfixes

* Fixed a problem with user configurations on Windows systems

# statR 2.3.0

## New Features
Expand Down
44 changes: 38 additions & 6 deletions R/user_config.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ getUserConfigs <- function() {
#' @param name The name of the configuration
#' @export
readUserConfig <- function(name = "default") {
config_path <- system.file("extdata/config/", package = "statR")
config_file <- paste0(config_path, name)

# config_path <- system.file("extdata/config/", package = "statR")
# config_file <- paste0(config_path, name)

config_path <- system.file("extdata/config", package = "statR")
config_file <- paste0(c(config_path, "name"), collapse = "/")

if (file.exists(config_file)) {
config <- yaml::read_yaml(config_file)
Expand All @@ -27,11 +31,36 @@ readUserConfig <- function(name = "default") {
#' @description Writes a user config into a YAML file
#' @param name Name of the configuration
#' @param config_list List of options set by user
#' @examples
#' \dontrun{
#' # statzh config list
#' config_list <- list(
#' statR_config_name = "statzh",
#' statR_organization = "Statistisches Amt des Kantons Zürich",
#' statR_name = "Datashop",
#' statR_phone = "+41 43 259 75 00",
#' statR_email = "datashop@statistik.zh.ch",
#' statR_homepage = "http://www.statistik.zh.ch",
#' statR_openinghours = c("Bürozeiten",
#' "Montag bis Freitag",
#' "09:00 bis 12:00",
#' "13:00 bis 16:00"),
#' statR_logo = "statzh",
#' statR_source = "Statistisches Amt des Kantons Zürich"
#' )
#'
#' # Write config list to disk
#' writeUserConfig("statzh", config_list)
#' }
#' @export
writeUserConfig <- function(name, config_list) {
config_path <- system.file("extdata/config/", package = "statR")
# config_path <- system.file("extdata/config/", package = "statR")
config_path <- system.file("extdata/config", package = "statR")
config_file <- paste0(c(config_path, "name"), collapse = "/")

config_list[["statR_config_name"]] <- name
yaml::write_yaml(config_list, paste0(config_path, name))
# yaml::write_yaml(config_list, paste0(config_path, name))
yaml::write_yaml(config_list, config_file)
}


Expand All @@ -51,8 +80,11 @@ getActiveConfigName <- function() {
#' startup
#' @export
setActiveConfig <- function(name, persistent = FALSE) {
config_path <- system.file("extdata/config/", package = "statR")
config_file <- paste0(config_path, name)
# config_path <- system.file("extdata/config/", package = "statR")
# config_file <- paste0(config_path, name)
config_path <- system.file("extdata/config", package = "statR")
config_file <- paste0(c(config_path, "name"), collapse = "/")


if (getActiveConfigName() != name & file.exists(config_file)) {
config <- yaml::read_yaml(config_file)
Expand Down
22 changes: 22 additions & 0 deletions man/writeUserConfig.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c7767b9

Please sign in to comment.