Skip to content

Commit

Permalink
feat: Control defaults by sys env
Browse files Browse the repository at this point in the history
  • Loading branch information
MEO265 committed Jun 2, 2024
1 parent de57b48 commit 1d0c42d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
37 changes: 37 additions & 0 deletions R/setup.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
setup_logfile <- function() {
logfile <- Sys.getenv(x = "FILE_LOGGIT2", unset = "")
call_arg <- list(confirm = FALSE, create = FALSE)
if (nchar(logfile) != 0L) call_arg <- c(logfile = logfile, call_arg)
do.call(set_logfile, call_arg)

Check warning on line 5 in R/setup.R

View check run for this annotation

Codecov / codecov/patch

R/setup.R#L2-L5

Added lines #L2 - L5 were not covered by tests
}

setup_timestamp_format <- function() {
ts_format <- Sys.getenv(x = "TIMESTAMP_LOGGIT2", unset = "")
call_arg <- list(confirm = FALSE)
if (nchar(ts_format) != 0L) call_arg <- c(ts_format = ts_format, call_arg)
do.call(set_timestamp_format, call_arg)

Check warning on line 12 in R/setup.R

View check run for this annotation

Codecov / codecov/patch

R/setup.R#L9-L12

Added lines #L9 - L12 were not covered by tests
}

setup_echo <- function() {
echo <- Sys.getenv(x = "ECHO_LOGGIT2", unset = "")
call_arg <- list(confirm = FALSE)
if (nchar(echo) != 0L) {
echo <- as.logical(echo)
if (!is.na(echo)) call_arg <- c(echo = echo, call_arg)

Check warning on line 20 in R/setup.R

View check run for this annotation

Codecov / codecov/patch

R/setup.R#L16-L20

Added lines #L16 - L20 were not covered by tests
}
do.call(set_echo, call_arg)

Check warning on line 22 in R/setup.R

View check run for this annotation

Codecov / codecov/patch

R/setup.R#L22

Added line #L22 was not covered by tests
}

setup_log_level <- function() {
log_level <- Sys.getenv(x = "LEVEL_LOGGIT2", unset = "")
call_arg <- list(confirm = FALSE)
if (nchar(log_level) != 0L) {
log_level <- tryCatch({
convert_lvl_input(log_level)
}, error = function(e) {
NULL

Check warning on line 32 in R/setup.R

View check run for this annotation

Codecov / codecov/patch

R/setup.R#L26-L32

Added lines #L26 - L32 were not covered by tests
})
call_arg <- c(level = log_level, call_arg)

Check warning on line 34 in R/setup.R

View check run for this annotation

Codecov / codecov/patch

R/setup.R#L34

Added line #L34 was not covered by tests
}
do.call(set_log_level, call_arg)

Check warning on line 36 in R/setup.R

View check run for this annotation

Codecov / codecov/patch

R/setup.R#L36

Added line #L36 was not covered by tests
}
8 changes: 4 additions & 4 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Set all default options on package load
.onLoad <- function(libname, pkgname) {
set_echo(confirm = FALSE)
set_log_level(confirm = FALSE, level = 4L)
set_logfile(confirm = FALSE, create = FALSE)
set_timestamp_format(confirm = FALSE)
setup_echo()
setup_log_level()
setup_logfile()
setup_timestamp_format()
}

0 comments on commit 1d0c42d

Please sign in to comment.