Skip to content

Commit

Permalink
refactor: Changed read_ and write_ params path functions to get_param…
Browse files Browse the repository at this point in the history
…s_path and set_params_path
  • Loading branch information
brycefrank committed Dec 28, 2023
1 parent 7cbcd20 commit f828e34
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
14 changes: 11 additions & 3 deletions R/load.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' @export
load_parameter_frame <- function(name) {
csv_name <- paste(name, ".csv", sep = "")
param_search_path <- read_params_path()
param_search_path <- get_params_path()

if(param_search_path == "package") {
file_path <- system.file(
Expand All @@ -24,13 +24,21 @@ load_parameter_frame <- function(name) {
tibble::as_tibble(table)
}

write_params_path_rds <- function(params_path) {
#' Set the parameter search path
#'
#' @param params_path The file path containing parameter files
#' @export
set_params_path <- function(params_path) {
params_path <- list(params_path = params_path)
rds_path <- file.path(system.file("extdata", package = "allometric"), "params_path.RDS")
saveRDS(params_path, rds_path)
}

read_params_path <- function() {
#' Get the parameter search path
#'
#' @return A string containing the currently set parameter search path
#' @export
get_params_path <- function() {
rds_path <- file.path(system.file("extdata", package = "allometric"), "params_path.RDS")
rds <- readRDS(rds_path)
rds$params_path
Expand Down
4 changes: 2 additions & 2 deletions R/publication_processing.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ map_publications <- function(verbose, func, pub_path = NULL, params_path = NULL)
}

if(!is.null(params_path)) {
write_params_path_rds(params_path)
set_params_path(params_path)
}

pub_specs <- get_pub_file_specs(pub_path)
Expand Down Expand Up @@ -178,7 +178,7 @@ map_publications <- function(verbose, func, pub_path = NULL, params_path = NULL)

# reset the param search path
if(!is.null(params_path)) {
write_params_path_rds("pacakge")
set_params_path("pacakge")
}

output
Expand Down
2 changes: 1 addition & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ suffixes <- utils::read.csv(

var_defs <- prepare_var_defs(var_defs_pre, measure_defs, component_defs)

write_params_path_rds("package")
set_params_path("package")

0 comments on commit f828e34

Please sign in to comment.